Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C Questions For Practice-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Classes By: K.K.

Singh, The Launcher Academy, City Center, Club Road, Ranchi


Mob. No: 8877155769

Programming in ‘C’

1. Rajesh’s basic salary is input through the keyboard. His dearness allowance is 40% of
basic salary, house rent allowance is 20% of basic salary and traveling allowance is
10% of basic salary. Write a program to calculate his gross salary.
2. The distance between two cities (in km.) is input through the keyboard. Write a
program to convert and print this distance in meters, feet, inches and centimeters.

3. If the marks obtained by a student in five different subjects are input through the
keyboard, find out the aggregate marks and percentage marks obtained by the student.
Assume that the maximum marks that can be obtained by a student in each subject is
100.

4. Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a


program to convert this temperature into Centigrade degrees.

5. The length & breadth of a rectangle are input through the keyboard. Write a program
to calculate the area & perimeter of the rectangle.

6. Write a program in C to print area and perimeter of a square if value of one side is
input through the keyboard.

7. -Write a program in C to print the volume and surface area of cuboids if length,width
and height are entered through keyboard.

(Volume = lbh and Surface Area =2(lw*wh*lh)

8. -Two numbers are input through the keyboard into two locations C and D. Write a
program to interchange the contents of C and D.
9. Write a program in C to print the volume and surface area of cube if length of one
side is entered through keyboard.

(Volume = side^3 and Surface Area =6(side^2))


10. Write a program in C to print the volume and surface area of sphere if the radius is
entered through keyboard.

(Volume =4/3 𝜋𝑟 3 and Surface Area =4𝜋𝑟 2)


11. Write a C program to find the Area and Volume of a Cone if the height and radius are
entered through keyboard.
(Volume =1/3 𝜋𝑟 2 h and Surface Area =𝜋𝑟(𝑟√𝑟 2 + h2 ) )

12. Write a C program to find the area of a triangle, given three sides
Classes By: K.K. Singh, The Launcher Academy, City Center, Club Road, Ranchi
Mob. No: 8877155769

13. Write a program in C to print the Area of Right Angled triangle if Base and Height is
given.
14. Write a C program to find the area and circumference of a circle, given the radius.
15. Write a C program to find the simple interest , given principle, rate of interest and
times
16. Write a C program to check whether a given integer is odd or even
17. Write a C program to check whether a given integer number is positive or negative
18. Write a C program to find the biggest of three numbers using nested if statement.
19. Write a C program to find and output all the roots of a quadratic equation, for non-
zero coefficients. In case of errors your program should report suitable error message
20. Write a C program to simulate a simple calculator to perform arithmetic operations
like addition, subtraction, multiplication and division only on integers. Error message
should be reported if any attempt is made to divide by zero
21. Write a C program to find the sum of 'N' natural numbers.
22. -Write a C program to find the sum of square of ‘N’ natural numbers using pointer.
23. Write a C program to find the biggest of three numbers using conditional operator.
24. If a five-digit number is input through the keyboard, write a program to calculate the
sum of its digits.

25. If a five-digit number is input through the keyboard, write a program to reverse the
number.

26. If a four-digit number is input through the keyboard, write a program to obtain the
sum of the first and last digit of this number.

27. Any integer is input through the keyboard. Write a program to find out whether it is
an odd number or even number

28. Any year is input through the keyboard. Write a program to determine whether the
year is a leap year or not.

29. A five-digit number is entered through the keyboard. Write a program to obtain the
reversed number and to determine whether the original and reversed numbers are
equal or not
Classes By: K.K. Singh, The Launcher Academy, City Center, Club Road, Ranchi
Mob. No: 8877155769

30. If the ages of Ram, Shyam and Ajay are input through the keyboard, write a program
to determine the youngest of the three

31. Write a program to check whether a triangle is valid or not, when the three angles of
the triangle are entered through the keyboard. A triangle is valid if the sum of all the
three angles is equal to 180 degrees

32. Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if all the
three points fall on one straight line.
33. In a town, the percentage of men is 52. The percentage of total literacy is 48. If total
percentage of literate men is 35 of the total population, write a program to find the
total number.
34. In a town, the percentage of men is 52. The percentage of total literacy is 48. If total
percentage of literate men is 35 of the total population, write a program to find the
total number of illiterate men and women if the population of the town is 80,000.
35. If the total selling price of 15 items and the total profit earned on them is input
through the keyboard, write a program to find the cost price of one item.
36. Enter any number and print its octal and hexadecimal equivalent number.
37. A library charges a fine for every book returned late. For first 5 days the fine is 50
paise, for 6-10 days 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 the book and display the fine or the
appropriate message.
38. 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 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.
39. If the three sides of a triangle are entered through the keyboard, write a program to
check whether the triangle is valid or not. The triangle is valid if the sum of two sides
is greater than the largest of the three sides.
40. If the three sides of a triangle are entered through the keyboard, write a program to
check whether the triangle is isosceles, equilateral, scalene or right angled triangle.
41. In a company, worker efficiency is determined on the basis of the time required for a
worker to complete a particular job. If the time taken by the worker is between 2 – 3
Classes By: K.K. Singh, The Launcher Academy, City Center, Club Road, Ranchi
Mob. No: 8877155769

hours, then the worker is said to be highly efficient. If the time required by the worker
is between 3 – 4 hours, then the worker is ordered to improve speed. If the time taken
is between 4 – 5 hours, the worker is given training to improve his speed, and if the
time taken by the worker is more than 5 hours, then the worker has to leave the
company. If the time taken by the worker is input through the keyboard, find the
efficiency of the worker.
42. A university has the following rules for a student to qualify for a degree with A as the
main subject and B as the subsidiary subject: (a) He should get 55 percent or more in
A and 45 percent or more in B. (b) If he gets than 55 percent in A he should get 55
percent or more in B. However, he should get at least 45 percent in A. (c) If he gets
less than 45 percent in B and 65 percent or more in A he is allowed to reappear in an
examination in B to qualify. (d) In all other cases he is declared to have failed. Write
a program to receive marks in A and B and Output whether the student has passed,
failed or is allowed to reappear in B.
43. The policy followed by a company to process customer orders is given by the
following rules: (a) If a customer order is less than or equal to that in stock and has
credit is OK, supply has requirement. (b) If has credit is not OK do not supply. Send
him intimation. (c) If has credit is Ok but the item in stock is less than has order,
supply what is in stock. Intimate to him data the balance will be shipped.
Write a C program to implement the company policy.

What will be the output of the following programs?

1.
#include<stdio.h>
int main()
{
int i=-3, j=2, k=0, m;
m = ++i && ++j && ++k;
printf("%d, %d, %d, %d\n", i, j, k, m);
return 0;
}
A. -2, 3, 1, 1 B. 2, 3, 1, 2
C. 1, 2, 3, 1 D. 3, 3, 1, 2

2.
#include<stdio.h>

int main()
{
printf("%x\n", -2<<2);
return 0;
}
A.ffff B.0
C.fff8 D.Error
Classes By: K.K. Singh, The Launcher Academy, City Center, Club Road, Ranchi
Mob. No: 8877155769

3.
#include<stdio.h>
int main()
{
int x=12, y=7, z;
z = x!=4 || y == 2;
printf("z=%d\n", z);
return 0;
}
A. z=0 B. z=1
C. z=4 D. z=2

4.
#include<stdio.h>
int main()
{
int i=4, j=-1, k=0, w, x, y, z;
w = i || j || k;
x = i && j && k;
y = i || j &&k;
z = i && j || k;
printf("%d, %d, %d, %d\n", w, x, y, z);
return 0;
}
A. 1, 1, 1, 1 B. 1, 1, 0, 1
C. 1, 0, 0, 1 D. 1, 0, 1, 1

5.
#include<stdio.h>
int main()
{
int i=-3, j=2, k=0, m;
m = ++i && ++j || ++k;
printf("%d, %d, %d, %d\n", i, j, k, m);
return 0;
}
A. 1, 2, 0, 1 B. -3, 2, 0, 1
C. -2, 3, 0, 1 D. 2, 3, 1, 1

6.
#include<stdio.h>
int main()
{
int x=4, y, z;
y = --x;
z = x--;
printf("%d, %d, %d\n", x, y, z);
return 0;
}
A. 4, 3, 3 B. 4, 3, 2
C. 3, 3, 2 D. 2, 3, 3

7.
Classes By: K.K. Singh, The Launcher Academy, City Center, Club Road, Ranchi
Mob. No: 8877155769

#include<stdio.h>
int main()
{
int i=3;
i = i++;
printf("%d\n", i);
return 0;
}
A. 3 B. 4
C. 5 D. 6

8.
#include<stdio.h>
int main()
{
int a=100, b=200, c;
c = (a == 100 || b > 200);
printf("c=%d\n", c);
return 0;
}
A. c=100 B. c=200
C. c=1 D. c=300

9.
#include<stdio.h>
int main()
{
int x=55;
printf("%d, %d, %d\n", x<=55, x=40, x>=10);
return 0;
}
A. 1, 40, 1 B. 1, 55, 1
C. 1, 55, 0 D. 1, 1, 1

10.
#include<stdio.h>
int main()
{
int i=2;
printf("%d, %d\n", ++i, ++i);
return 0;
}
A. 3, 4
B. 4, 3
C. 4, 4
D. Output may vary from compiler to compiler

11.
#include<stdio.h>
int main()
{
int k, num=30;
k = (num>5 ? (num <=10 ? 100 : 200): 500);
printf("%d\n", num);
return 0;
Classes By: K.K. Singh, The Launcher Academy, City Center, Club Road, Ranchi
Mob. No: 8877155769

}
A. 200 B. 30
C. 100 D. 500

12.
#include<stdio.h>
int main()
{
char ch;
ch = 'A';
printf("The letter is");
printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A':ch);
printf("Now the letter is");
printf("%c\n", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A');
return 0;
}
The letter is a The letter is A
A. B.
Now the letter is A Now the letter is a
C.Error D.None of above

13.
#include<stdio.h>
int main()
{
int i=2;
int j = i + (1, 2, 3, 4, 5);
printf("%d\n", j);
return 0;
}
A. 4 B. 7
C. 6 D. 5

14.
int main()
{
int x,y,z;
x=2+3-4+5-(6-7);
y=2*33+4*(5-6);
z=2*3*4/15%13;
printf("%d %d %d",x,y,z);
x=2+33% -5/4;
y=2-33% -5/-4;
z=-2*-3/-4% -5;
printf("\n%d %d %d",x,y,z);
return 0;
}

15.
int main()
{
int x=3,y=5,z=7,w;
w=x%y+y%x-z%x-x%z;
printf("%d",w);
w=x/z+y/z+(x+y)/z;
Classes By: K.K. Singh, The Launcher Academy, City Center, Club Road, Ranchi
Mob. No: 8877155769

printf("\n%d",w);
w=x/z*y/z+x*y/z;
printf("\n%d",w);
w=x%y%z+z%y%(y%x);
printf("\n%d",w);
w=z/y/y/x+z/y/(y/x);
printf("\n%d",w);
return 0;
}

16.
int main()
{
int x=3,y=5,z=7,w=9;
w+=x+y-(z-=w);
printf("%d",w);
w+=x-=y%=z;
printf("\n%d",w);
return 0;
}

17.
int main()
{
int x=7,y=-7,z=11,w=-11,s=9,t=10;
x+=(y-=(z*=(w/=(s%=t))))
printf("%d %d %d %d %d %d",x,y,z,w,s,t);
t+=s-=w*=z*=y%=x;
printf("\n%d %d %d %d %d %d",x,y,z,w,s,t);
return 0;
}

18.
int main()
{
float c=3.14;
printf("%f",c%2);
return 0;
}

19.
int main()
{
double d=1/2.0 - 1/2;
printf("%.2lf",d);
return 0;
}

20.
int main()
{
unsigned int c=-2;
printf("%u",c);
return 0;
}
Classes By: K.K. Singh, The Launcher Academy, City Center, Club Road, Ranchi
Mob. No: 8877155769

21.
int main()
{
char c='A';
printf("%c",c+10);
return 0;
}

22.
int main()
{
int a;
a=printf("good")+printf("boy");
printf("%d",a);
return 0;
}

23.
int main()
{
printf("Work" "Hard");
return 0;
}

24.
int main()
{
int a=5;
i=!a>10;
printf("%d",i);
return 0;
}

25.
int main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
return 0;
}

26.
int main()
{
printf("%d %d %d",i++,i,++i);
return 0;
}

27.
int main()
{
int i;
printf("%d",scanf("%d",&i));
return 0;
Classes By: K.K. Singh, The Launcher Academy, City Center, Club Road, Ranchi
Mob. No: 8877155769

28.
int main()
{
int x=1,y=5;
printf("%d",++(x+y));
return 0;
}

29.
int main()
{
int a=7,b=2;
float c;
c=a/b;
printf("%f",c);
return 0;
}

30.
int main()
{
int c=1;
c=c+2*c++;
return 0;
}

31.
int main()
{
int value=5;
printf("%s", !(value%2)?"yes":"no");
return 0;
}

32.
int main()
{
int x=20,y=35;
x=y++ + x++;
y=++y + ++x;
printf("%d %d",x,y);
return 0;
}

33.
int main()
{
int x=5;
printf("%d %d %d",x,x<<2,x>>2);
return 0;
}
Classes By: K.K. Singh, The Launcher Academy, City Center, Club Road, Ranchi
Mob. No: 8877155769

34.
int main()
{
int a=2,b=3;
printf("%d",a+++b);
printf(" %d %d",a,b);
return 0;
}

35.
int main()
{
int c=1;
while(c<=5)
{
if(c==3)
break;
printf("\n%d",c);
c++;
}
return 0;
}

36.
int main()
{
int c=1;
while(c<=5)
{
if(c==3)
continue;
printf("%d",c);
c++;
}
return 0;
}

37.
int main( )
{
int i = 4, j = -1, k = 0, w, x, y, z ;
w = i || j || k ;
x = i && j && k ;
y = i || j && k ;
z = i && j || k ;
printf ( "\nw = %d x = %d y = %d z = %d", w, x, y, z );
return 0;
}

38.
int main()
{
int i = 4, j = -1, k = 0, y, z ;
y = i + 5 && j + 1 || k + 2 ;
z = i + 5 || j + 1 && k + 2 ;
Classes By: K.K. Singh, The Launcher Academy, City Center, Club Road, Ranchi
Mob. No: 8877155769

printf ( "\ny = %d z = %d", y, z );


return 0;
}

39.
int main()
{
int tag = 0, code = 1 ;
if ( tag == 0 )
( code > 1 ? printf ( "\nHello" ) ? printf ( "\nHi" ) ) ;
else
printf ( "\nHello Hi !!" );
return 0;
}

40.
int main()
{
char ch=’A’;
printf(“%d %d”,sizeof(ch),sizeof(‘A’));
Return 0;
}

41.
int main()
{
int x=2;
printf(“%d”,x*=3/2);
}

42.
int main()
{
int x=40,y;
y=x>>2<<3>>3;
printf(“%d”,y);
return 0;
}

43.
int main()
{
float x=3.4565E+02;
if(x==345.65)
printf("Equal");
else
printf("Not Equal");
return 0;
}

You might also like