Sunday, April 19, 2015

C Programming Sheet-2

CHECK OUT HERE AND FIND AMAZING STUFF HERE


Topics Covered:-
Ø Decision Control and Conditional Operators

1.     Any character is entered through the keyboard; write a program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol. The following table shows the range of ASCII values for various characters.

Characters
ASCII Values
A-Z
65-90
a-z
97-122
0-9
48-57
Special symbols
0-47,58-64,91-96,123-127

2.     A certain grade of steel is graded according to the following conditions:-
       i.            Hardness must be greater than 50
     ii.            Carbon content must be less than 0.7
  iii.            Tensile strength must be greater than 5600

The grades are as follows:

Grade is 10 if all the three conditions are met
Grade is 9 if conditions (i) and (ii) are met
Grade is 8 if conditions (ii) and (iii) are met
Grade is 7 if conditions (i) and (iii) are met
Grade is 6 if only one condition is met
Grade is 5 if none of the conditions are met

Write a program, which will require the user to give values of hardness, carbon content and tensile strength of the steel under consideration and output the grade of the steel.

3.     A library charges a fine for every book returned late. For first 5 days the fine is 50 paise, for 6-10 fine is one rupee and above 10 days fine is 5 rupees. If you return the book after 30 days your membership will be cancelled. Write a program to accept the number of days the member is late to return book and display the fine or the appropriate message.


Ø Case Control Structure (Switch statement)

1.      WAP using switch case statement in C
Prompt the user to enter the grade of a student. Print message as mentioned below:-
Grade A:-Excellent
Grade B:-Good
Grade C:-Ok
Grade D:-Poor

2.     Write a menu driven program which has the following options:-
1.     Factorial of a number
2.     Prime or not
3.     Odd or even
4.     Exit
Once a menu item is selected the appropriate action should be taken.
3.     WAP to find the grace marks for a student using switch. The user should enter the class obtained by the student followed by the number of subjects he has failed in. Use the following logic:-
  Ø If the student gets first class and the number of subjects he failed in is greater                  than 3, then he does not get any grace. If the number of subjects he failed in is                less than or equal to 3, then the grace is of 5 marks per subject.
  Ø If the student gets a second class and the number of subjects he failed in is greater         than 2, then he does not get any grace. If the number of subjects he failed in is less         than or equal to 2, then the grace is of 4 marks per subject.

  Ø If the student gets third class and the number of subjects he failed in is greater than 1, then he does not get any grace. If the number of subjects he failed in is equal to 1, then the grace is of 5 marks per subject.

C Programming Sheet-1

CHECK OUT HERE AND FIND AMAZING STUFF HERE
        
    Topics Covered:-
1.    Variables and Data types
2.    Arithmetic and Compound Operators
3.    Increment and Decrement Operators

1.      If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.
2.      Temperature of a city in Fahrenheit degrees his input through the keyboard. Write a program to convert this temperature into Centigrade degrees.
3.      If a four digit number is input through the keyboard, write a program to reverse the number.
4.      In a town, the percentage of men is 52.The percentage of total literacy is 48.If the total percentage of literate men is 35 out of the total population, write a program to calculate the total number of illiterate men and women. Total population of the town is 80,000.
5.      Write a program  to produce the following output :-

                                  i.            Initialize x to 10
                                ii.            Calculate y=x++. Output x and y
                              iii.            Calculate z=++x. Output x and z
                              iv.            Calculate a=x--. Output x and a
                                v.            Calculate b=--x. Output x and b
















Ø  Decision Control Structure

6.      While purchasing certain items, a discount of 10% is offered if the quantity purchased is more than 1000.If quantity and price per item are input through the keyboard, write a program to calculate the total expenses.
7.      In a company an employee is paid as below :-
8.      If his basic salary is less than Rs 1500, then HRA = 10% of basic salary and DA=90% of basic salary. If his salary is either equal to or above Rs 1500, then HRA=Rs500 and DA=98% of basic salary. If the employee’s salary is input through the keyboard write a program to find his gross salary.
9.      If the cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred.
10.  Any year is input through the keyboard. Write a program to determine whether the year is a leap year or not.


Tuesday, October 14, 2014

9teen sample C programs

CHECK OUT HERE AND FIND AMAZING STUFF HERE

Visit this link for online earning really working Simple to get in and earn i assure you that

1. What will be output when you will execute following c code?

#include<stdio.h>void main(){int a=5,b=10,c=1;if(a&&b>c){printf("your own blog");}else{break;}}

Choose all that apply:

(A) your own blog(B) It will print nothing(C) Run time error(D) Compilation error
(E) None of the above

Explanation:Keyword break is not syntactical part of if-else statement. So we cannot use break keyword in if-else statement. This keyword can be use in case of loop or switch case statement. Hence when you will compile above code compiler will show an error message: Misplaced break.

2.

What will be output when you will execute following c code?

#define PRINT printf("StarDust");printf(" SHOOTER");#include<stdio.h>void main(){int x=1;if(x--)PRINTelseprintf("The Shawshank Redemption");}

Choose all that apply:

(A) StarsDust SHOOTER(B) The Shawshank Redemption(C) Warning: Condition is always true(D) Warning: Condition is always false





3.

What will be output when you will execute following c code?

#define True 5==5#include<stdio.h>void main(){if(.001-0.1f)printf("David Beckham");else if(True)printf("Ronaldinho");elseprintf("Cristiano Ronaldo");}

Choose all that apply:

(A) David Beckham(B) Ronaldinho
(C) Cristiano Ronaldo(D) Warning: Condition is always true(E) Warning: Unreachable code





4.

What will be output when you will execute following c code?

#include<stdio.h>void main(){int a=100;if(a>10)printf("M.S. Dhoni");else if(a>20)printf("M.E.K Hussey");else if(a>30)printf("A.B. de villiers");}

Choose all that apply:

(A) M.S. Dhoni(B) A.B. de villiers(C) M.S Dhoni M.E.K Hussey A.B. de Villiers(D) Compilation error: More than one conditions are true(E) None of the above




5.

What will be output when you will execute following c code?

#include<stdio.h>void main(){int x=-1,y=-1;if(++x=++y)printf("R.T. Ponting");elseprintf("C.H. Gayle");}

Choose all that apply:

(A) R.T Ponting(B) C.H. Gayle(C) Warning: x and y are assigned a value that is never used(D) Warning: Condition is always true(E) Compilation error





6.

What will be output when you will execute following c code?

#include<stdio.h>void main(){if(sizeof(void))printf("M. Muralilidaran");elseprintf("Harbhajan Singh");}

Choose all that apply:

(A) M. Muralilidaran(B) Harbhajan Singh(C) Warning: Condition is always false(D) Compilation Error(E) None of the above







7.

What will be output when you will execute following c code?

#include<stdio.h>void main(){int m=5,n=10,q=20;if(q/n*m)printf("William Gates");elseprintf(" Warren Buffet");printf(" Carlos Slim Helu");}

Choose all that apply:(A) William Gates(B) Warren Buffet Carlos Slim Helu(C) Run time error(D) Compilation error




8.

What will be output when you will execute following c code?

#include<stdio.h>void main(){if(!printf("Mukesh Ambani"))if(printf(" Lakashmi Mittal"));}

Choose all that apply:

(A) Mukesh Ambani(B) Lakashmi Mittal(C) It will print nothing(D) Mukesh Ambani Lakashmi Mittal(E) Compilation error: if statement without body



9.

What will be output when you will execute following c code?

#include<stdio.h>void main(){if("ABC") printf("Barack Obama\n");if(-1) printf("Hu Jintao\n");if(.92L) printf("Nicolas Sarkozy\n");if(0) printf("Ben Bernanke\n");if('W') printf("Vladimir Putin\n");}

Choose all that apply:

(A) It will print nothing(B) Barack ObamaHu JintaoNicolas SarkozyVladimir Putin(C) Barack ObamaHu JintaoNicolas SarkozyBen BernankeVladimir Putin
(D) Hu JintaoNicolas SarkozyVladimir Putin (E) Compilation error



10.

What will be output when you will execute following c code?

#include<stdio.h>void main(){if(0xA)if(052)if('\xeb')if('\012')printf("Tom hanks");else;else;else;else;}

Choose all that apply:

(A) Tom hanks(B) Compilation error: Misplaced else(C) Compilation error: If without any body(D) Compilation error: Undefined symbol(E) Warning: Condition is always true



11.

What will be output when you will execute following c code?

#include<stdio.h>void main(){int a=10;if(printf("%d",a>=10)-10)for(;;)break;else;}

Choose all that apply:

(A) It will print nothing(B) 0(C) 1(D) Compilation error: Misplaced else(E) Infinite loop



12.

What will be output when you will execute following c code?

#include<stdio.h>void main(){int a=5,b=10;if(++a||++b)printf("%d %d",a,b);elseprintf("John Terry");}

Choose all that apply:

(A) 5 10(B) 6 11(C) 6 10(D) 5 11(E) John Terry

Explanation:

Consider the following expression:++a || ++b

In this expression || is Logical OR operator. Two important properties of this operator are:Property 1:(Expression1) || (Expression2)|| operator returns 0 if and only if both expressions return a zero otherwise it || operator returns 1.

Property 2:

To optimize the execution time there is rule, Expression2 will only evaluate if and only if Expression1 return zero.

In this program initial value of a is 5. So ++a will be 6. Since ++a is returning a non-zero so ++b will not execute and if condition will be true and if clause will be executed.

13.

What will be output when you will execute following c code?

#include<stdio.h>void main(){static int i;for(;;)if(i+++"The Matrix")printf("Memento");elsebreak;}

Choose all that apply:

(A) It will print Memento at one time(B) It will print Memento at three times(C) It will print Memento at ten times(D) It will print Memento at infinite times(E) Compilation error: Unknown operator +++





14.

What will be output when you will execute following c code?

#include<stdio.h>void main(){int x=1;if(x--)printf("The Godfather");--x;elseprintf("%d",x);}

Choose all that apply:

(A) The Godfather(B) 1(C) 0(D) Compilation error(E) None of the above






15.

What will be output when you will execute following c code?

#include<stdio.h>void main(){if('\0');else if(NULL)printf("Whats_ur_RASHI??Yeah to bata DO");else;}

Choose all that apply:

(A) Whats_ur_RASHI??Yeah to bata DO(B) It will print nothing(C) Warning: Condition is always true(D) Warning: Unreachable code(E) Compilation error: if statement without any body





16.

What will be output when you will execute following c code?

#include<stdio.h>void main(){int a=5,b=10;if(a<++a||b<++b)printf("%d %d",a,b);elseprintf("John Terry");}

Choose all that apply:

(A) 5 10(B) 6 11(C) 6 10(D) Compilation error(E) John Terry





17.

What will be output when you will execute following c code?

#include<stdio.h>void main(){int x=1,y=2;if(--x && --y)printf("x=%d y=%d",x,y);elseprintf("%d %d",x,y);}

Choose all that apply:

(A) 1 2(B) x=1 y=2(C) 0 2(D) x=0 y=1(E) 0 1






18.

What will be output when you will execute following c code?

#include<stdio.h>void main(){signed int a=-1;unsigned int b=-1u;if(a==b)printf("LOTS OF LOVE");elseprintf("LAUGH OUT LOUD");}

Choose all that apply:

(A) LOTS OF LOVE(B) LAUGH OUT LOUD(C) Compilation error: Cannot compare signed number with unsigned number(D) Compilation error: Undefined symbol -1u(E) Warning: Illegal operation

19.

What will be output when you will execute following c code?

#include<stdio.h>void main(){char cc=256;char *ptrr="Lenny";if(cc==0)
while(!cc)if(*ptrr++)printf("%+u",cc);elsebreak;}

Choose all that apply:

(A) +256+256+256+256(B) 00000(C) +0+0+0+0(D) It will print +256 at infinite times(E) Compilation error



20.

What will be output when you will execute following c code?

#include<stdio.h>void main(){int a=2;if(a--,--a,a)printf("MAMA’s BOY");elseprintf("I LUV MY DAD");}

Choose all that apply:

(A) MAMA’s BOY(B) I LUV MY DAD(C) Run time error(D) Compilation error: Multiple parameters in if statement(E) None of the above