Chapter # 4 Important Practical Questions for Paper
Q # 1 → Write a program that inputs Q # 2 → Write a program inputs two
marks and display “Congratulations You numbers, check 2nd number is square of have Passed” if the marks are 40 or the 1st number. more. Void main ( ) Void main ( ) { int marks ; { int a , b ; printf(“Enter value of 1st Number = ” ) ; printf(“Enter Marks = ” ) ; scanf(“ %d ”, & a ) ; scanf(“ %d ”, & marks ) ; printf(“Enter value of 2nd Number = ” ) ; scanf(“ %d ”, & b ) ; if ( marks >= 40 ) if ( a = b * b ) printf(“ Congratulations! You have Passed ” ) ; printf(“ 2nd Num is Square of 1st Num ” ) ; } } Q # 3 → Write a program that input three Q # 4 → Write a program that inputs a numbers and displays the maximum number and find whether it is Even or number. Odd using if-else. Void main ( ) Void main ( ) { int a , b , c ; { printf(“ Enter value of a = ” ) ; int a ; scanf(“ %d ”, & a ) ; printf(“ Enter value of b = ” ) ; printf(“ Enter value of a = ” ) ; scanf(“ %d ”, & b ) ; scanf(“ %d ”, & a ) ; printf(“ Enter value of c = ” ) ; scanf(“ %d ”, & c ) ; if ( a % 2 == 0 ) if ( a > b && a > c ) printf(“ A is Even ” ) ; printf(“ A is Maximum ” ) ; else else if ( b > a && b > c ) printf(“ A is Odd ” ) ; printf(“ B is Maximum ” ) ; } else if ( c > a && c > b ) printf(“ C is Maximum ” ) ; } Q # 5 → Write a program that inputs two Q # 6 → Write a program that inputs a numbers and find whether these number. It displays square root of the numbers are equal or not using if-else number it the number is positive structure. otherwise the program displays a message “Invalid Input”’. Void main ( ) Void main ( ) { int a , b ; { int a ; printf(“ Enter value of a = ” ) ; scanf(“ %d ”, & a ) ; printf(“ Enter value of a = ” ) ; printf(“ Enter value of b = ” ) ; scanf(“ %d ”, & a ) ; scanf(“ %d ”, & b ) ; if ( a == b ) if ( a > 0 ) printf(“ Numbers are Equal ” ) ; printf(“ Square Root = % d ”, sqrt (a) ) ; else else printf(“ Numbers are not Equal ” ) ; printf(“ Invalid Input ” ) ; } } Q # 7 → Write a program that inputs a Q # 8 → Write a program that inputs year and finds whether it is a leap year salary and grade. It adds 50% bonus if or not, using if-else-if structure. the grade is greater than 15. It adds 25% bonus if the grade is 15 or less and then displays the total salary. Void main ( ) Void main ( ) { { int year ; int sal ; printf(“Enter Year to check if it is leap year ” ) ; printf(“Enter Your Salary = ” ) ; scanf(“ %d ”, & year) ; scanf(“ %d ”, & sal) ; if ( year % 400 = = 0 ) if ( sal > 15 ) printf(“ %d is a leap year”, year ) ; { sal = sal + (sal * 0.5) ; else if ( year % 100 = = 0 ) printf(“ %d is total Salary”, sal ) ; printf(“ %d is not a leap year”, year ) ; } else if ( year % 4 = = 0 ) else if ( sal < = 15 ) printf(“ %d is a leap year”, year ) ; { sal = sal + (sal * 0.25) ; else printf(“ %d is total Salary”, sal ) ; printf(“ %d is not a leap year”, year ) ;} } } Q # 9 → Write a program that inputs a Q # 10 → Write a program that input number from the user and determine salary. It the salary is 20,000 or more, it whether it is positive, negative or zero. deducts 7% of the salary. It the salary is 10,000 or more but less than 20,000 it deducts 1000 from the salary. If salary is less than 10,000 it deducts nothing. Void main ( ) Void main ( ) { { int num ; int sal ; printf(“Enter Number ” ) ; printf(“Enter Your Salary = ” ) ; scanf(“ %d ”, & num) ; scanf(“ %d ”, & sal) ; if ( num > 0 ) if ( sal > = 20000 ) printf(“ %d is Positive ”, num ) ; { sal = sal - (sal * 0.07) ; else if ( num < 0 ) printf(“ %d is total Salary ”, sal ) ; printf(“ %d is Negative ”,num ) ; } else if ( num = = 0 ) else if ( sal > = 10000 && sal < 20000 ) printf(“ %d is Zero ”, num ) ; { sal = sal - 1000 ; } printf(“ %d is total Salary ”, sal ) ; } else printf(“ %d is a Salary “, sal ) ; } Q # 11 → Write a program that inputs Q # 12 → Write a program to calculate test score of a student and displays its the electricity bill. The rates of electricity grade according to given criteria. per unit are as follows: If units consumed are <= 300, A if score is >= 90 then the cost is Rs=2/unit. B if score is between 80 – 89 It units consumed are > 300 and < C if score is between 70 – 79 500, then the cost is Rs=5/unit. D if score is between 60 – 69 If units consumed exceed 500, F if below 60 then the cost Rs=7/unit. A line rent Rs=150 is also added to the total bill and surcharge of 5% extra if the bill exceeds Rs=2000. Calculate the total with all conditions given above. Void main ( ) Void main ( ) { { int marks ; int units, bill ; printf(“Enter Your marks = ” ) ; printf(“Enter Your Units = ” ) ; scanf(“ %d ”, & marks) ; scanf(“ %d ”, & units) ; if ( marks > = 90 ) if ( units > 500 ) printf(“ A ” ) ; { bill = 150 + units * 7 ; else if ( marks > = 80 && marks < 90 ) If ( bill > 2000 ) printf(“ B ” ) ; bill = bill + ( bill * 0.05 ); else if ( marks > = 70 && marks < 80 ) printf(“ %d is Your Bill ”, bill ) ; printf(“ C ” ) ; } else if ( marks > = 60 && marks < 70 ) else if ( units > 300 && sal < = 500 ) printf(“ D ” ) ; { bill = 150 + units * 5 ; else If ( bill > 2000 ) printf(“ F ” ) ; bill = bill + ( bill * 0.05 ); } printf(“ %d is Your Bill ”, bill ) ; } else if ( units < = 300 ) { bill = 150 + units * 2 ; printf(“ %d is Your Bill ”, bill ) ; } } Q # 13 → Write a program that inputs Q # 14 → Write a program that input radius. It calculates area of circle if user three numbers and displays the smallest enters 1 as choice. It calculates using nested-if. circumference if the user enters 2 as choice. Void main ( ) Void main ( ) { { int a, b, c ; int choice , radius ; printf(“Enter Value of a, b ,c = ” ) ; printf(“Enter radius = ” ) ; scanf(“ %d, %d, %d ”, & a, & b, & c ) ; scanf(“ %d ”, & radius ) ; if ( a < b ) printf(“Enter choice 1 for Area, 2 for circurference ” ) ; { if ( a < c ) switch ( choice ) printf(“ A is Smallest ” ) ; } { case 1 : if ( b < a ) Printf (“Area = % f “, 3.14 * radius * radius ) ; { if ( b < c ) break; printf(“ B is Smallest ” ) ; } case 2 : if ( c < a ) Printf (“Circumference = % f “, 2 * 3.14 * radius ) ; { if ( c < b ) } printf(“ C is Smallest ” ) ; } } } Q # 15 → Write a program that inputs Q # 16 → Write a program that inputs three numbers and displays whether all three numbers and displays the numbers are equal or not by using maximum number by using logical nested-if condition. operators. Void main ( ) Void main ( ) { { int a, b, c ; int a, b, c ; printf(“Enter Value of a, b ,c = ” ) ; printf(“Enter Value of a, b ,c = ” ) ; scanf(“ %d, %d, %d ”, & a, & b, & c ) ; scanf(“ %d, %d, %d ”, & a, & b, & c ) ; if ( a > b && a > c ) if ( a = = b ) printf(“ %d is Maximum ”, a ) ; { if ( b = = c ) else if ( b > a && b > c ) printf(“ All Numbers are Equal ” ) ; } printf(“ %d is Maximum ”, b ) ; else else if ( c > a && c > b ) printf(“ Numbers are not Equal ” ) ; } printf(“ %d is Maximum ”, c ) ; } } Q # 17 → Write a program that inputs a Q # 18 → Write a program that allows character and displays whether it is the user any character through the Vowel or Consonant. keyboard and determine whether it is a capital letter, small case letter, a digital number or a special symbol. Void main ( ) Void main ( ) { char ch ; { printf(“Enter Character = ” ) ; char ch ; scanf(“ % c ”, & ch ) ; switch ( ch ) printf(“Enter Character = ” ) ; { case ‘a’ : case ‘A’ : scanf(“ % c ”, & ch ) ; Printf ( “ Wovel ” ) ; break; case ‘e’ : case ‘E’ : if ( ch > = ‘a’ && ch < = ‘z’ ) Printf ( “ Wovel ” ) ; break; Printf ( “ %c is Lower-case Alphabet “, ch ) ; case ‘i’ : case ‘I’ : Printf ( “ Wovel ” ) ; break; else if ( ch > = ‘A’ && ch < = ‘Z’ ) case ‘o’ : case ‘O’ : Printf ( “ %c is Upper-rcase Alphabet “, ch ) ; Printf ( “ Wovel ” ) ; break; case ‘u’ : case ‘U’ : else if ( ch > = ‘0’ && ch < = ‘9’ ) Printf ( “ Wovel ” ) ; break; Printf ( “ %c is Digit “, ch ) ; default : printf ( “ Consonant “ ) ; else } Printf ( “ %c is Special Character “, ch ) ; } } Q # 19 → Write a program that inputs a Q # 20 → Write a program that inputs a number and displays whether it is even number of weekdays and displays the or odd by using Conditional operator “ ? name of the day. For example if the user “. press 1, it displays “Monday”, 2 then “Tuesday” and so on. Void main ( ) Void main ( ) { { int a ; int a ; printf(“Enter Value = ” ) ; printf(“ Enter Value of A = ” ) ; scanf(“ % d ”, & a ) ; scanf(“ %d ”, & a ) ; switch ( a ) { case 1 : (a % 2 = = 0) ? printf (“ Even ” ) : printf (“ Odd ” ) ; Printf ( “ Friday ” ) ; break; } case 2 : Printf ( “ Saturday ” ) ; break; case 3 : Printf ( “ Sunday ” ) ; break; case 4 : Printf ( “ Monday ” ) ; break; case 5 : Printf ( “ Tuesday ” ) ; break; case 6 : printf ( “ Wednesday “ ) ; break; case 7 : printf ( “ Thursday “ ) ; break; default: printf ( “ Invalid Number “ ) ; } } Q # 21 → Write a program that inputs Q # 22 → Write a program that input two two numbers and one arithmetic numbers and displays which number is operator. It applies arithmetic operation larger using conditional operator. on numbers on the basis of the operator by using switch statement.
OR
Write a simple calculator by using Switch
statement. Void main ( ) Void main ( ) { char ch ; int a, b ; { printf(“Enter Numbers = ” ) ; int a, b ; scanf(“ % d % d”, & a, &b ) ; printf(“Enter Operator = ” ) ; printf(“ Enter Value of A & B = ” ) ; scanf(“ % c”, & ch ) ; scanf(“ %d %d ”, & a, & b ) ; switch ( ch ) { case ‘ + ’ : (a > b) ? printf (“A is Max ”) : printf (“B is Max ”) ; Printf (“ Sum of a & b = %d ”, a+b) ; break; } case ‘ - ’ : Printf (“ Sub of a & b = %d ”, a-b) ; break; case ‘ * ’ : Printf (“ Mul of a & b = %d ”, a*b) ; break; case ‘ / ’ : Printf (“ Div of a & b = %d ”, a/b) ; break; default : printf ( “ Invalid Operator “ ) ; } } Q # 23 → Write a program that inputs a Q # 24 → Write a program that inputs x number and displays whether it is and y-coordinate. On the basis of these divisible by 3 or not by using conditional coordinates the program will display to operator. which quarter these coordinates belong. Void main ( ) Void main ( ) { { int a ; int x, y ; printf(“ Enter Value of X & Y = ” ) ; printf(“ Enter Value of A = ” ) ; scanf(“ %d %d ”, & x, & y ) ; scanf(“ %d ”, & a ) ; if ( x > 0 && y > 0) printf (“ Lies in 1st Quadrant ”) ; (a % 3 == 0) ? printf (“A is divisible by 3 ”) : else if ( x < 0 && y > 0) printf (“ A is not divisible by 3 ”) ; printf (“ Lies in 2nd Quadrant ”) ; } else if ( x < 0 && y < 0) printf (“ Lies in 3rd Quadrant ”) ; else if ( x > 0 && y < 0) printf (“ Lies in 4th Quadrant ”) ; } Q # 25 → Write a program that reads the value of temperature and display “Hot Day” if temp > 35, “Pleasant Day” if temp between 25 and 35, “Cool Day”, if temp < 25. Void main ( ) { int temp ;
printf(“ Enter Temperature = ” ) ;
scanf(“ %d ”, & temp ) ; if ( temp > 35 ) printf (“ Hot Day ”) ; else if ( temp > 25 && temp < = 35) printf (“ Pleasant Day ”) ; else if ( temp < 25) printf (“ Cool Day ”) ; }