0% found this document useful (0 votes)
22 views

Assignment 4

The document contains 17 programming problems involving concepts like if-else statements, switch statements, arithmetic operations, and logical comparisons. The problems cover a range of skills including reading input, performing calculations, and printing output based on conditional logic. Example inputs and outputs are provided for many of the problems.

Uploaded by

AYAN PANJA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Assignment 4

The document contains 17 programming problems involving concepts like if-else statements, switch statements, arithmetic operations, and logical comparisons. The problems cover a range of skills including reading input, performing calculations, and printing output based on conditional logic. Example inputs and outputs are provided for many of the problems.

Uploaded by

AYAN PANJA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Switch and Condition

#include<stdio.h> #include<math.h>//ax2+bx+c=0; main( main( )


main( ) ) {int x,y,z;
{ float a,b,m; { float a,b,c,det,r1,r2; printf(“give x”);
printf(“Two numbers”); printf(“\nGive a b c”); scanf(“%d”,&x);
scanf(“%f %f”,&a,&b); scanf(“%f %f %f”,&a,&b,&c); switch(x)
if (a>b) m=a; else m=b; det=b*b4*a*c; { case 12: y=x+10; break;
printf(“%f bigger”,m); if(det<0) printf(“Imaginary”); case 7: z=x*x; y=z+6;
} Bigger of two numbers else break;
1. Write program, which { r1=(b+sqrt(det))/(2*a); default: y=2*x; break;
reads three numbers and r2=(bsqrt(det))/(2*a); }
prints the biggest. printf(“roots %f %f”,r1,r2); printf(“%d \n”,y);
2. Write program, which } } 12  22 13  26 7  55
reads four numbers and } compile as cc t.c -lm Remove first break
prints the biggest. input 1,5,6  -2,-3 i/p2,3,4  im on i/p 12 o/p is 150
3. Write program, which reads 2 numbers and prints both of them. The bigger number is printed first.
4. Write program, which reads a, b and c. Let ax2 + bx + c = 0 be a quadratic equation. If roots are real
and distinct then both roots are printed. If roots are equal then only one root is printed. If roots are
imaginary then real part and complex parts of both roots are printed. E.g. if input is a=1 b=8 c=25
then output is –4, 3 and –3. If input a=2 b=8 c=8 output 2. Input 2 10 12 output 3 and 2.
5. Modify above program to print roots. E.g. for above input output 4+3i and 43i.
6. Write program, which reads a, b and c as sides of a triangle and prints whether angle A is 90 0 or
not.
[Hint: if (a2 = = b2+c2) ] [Do not use cos1 etc]
7. Write program, which reads a, b, and c. Let ax + by + c = 0 be equation of a line. Print its slope.
The program also prints whether the line is vertical or not.
8. Write program, which reads three numbers. Two of these are same and one of them is different. The
program outputs the different number. e.g. input 5 5 2 output 2. Input 4 3 4 output 3. Input 5 2 2
output 5.
9. Write program, which reads 5 numbers a, b, c, d, and x. Here a, b, c, and d are distinct and x is equal
to exactly one of a or b or c or d. The program output which is equal to x. e.g. input 5 7 9 6 7 output
x is equal to b. input 8 7 1 3 1 output x is equal to c.
10. Write program, which reads 5 numbers a, b, c, d, and x. The program output how many among a,
b, c and d are equal to x. e.g. input 5 7 9 7 7 output 2. Input 5 3 8 7 2 output 0. Input 5 2 2 2 5 output
1.
11. Write program, which reads three numbers. The program outputs the middle of these. 5,2,4  4.
5,6,2  5.
12. Read p, q, r, a, b, c. Let ax+by+c=0 be a line. Let (p,q) be the center of a circle and r be its radius.
The program finds whether the circle and the line intersect or not. If they intersect let A and B be
the points of intersection of the circle and the line. Find the area of the triangle formed by A, B and
the center of the circle. [Hint: Find the distance of the line from the center. If it is more than the
radius then circle and the line do not intersect. Otherwise find the chord length AB]. Input 5 4 10 1
1 20  “no intersection”. Input 7 4 13 3 4 23  60.
13. Write program, which reads an integer X and prints an integer Y. Y is X+10 if X is between 10 and
30. Y is 3*X if X is between 50 and 70. Otherwise Y is X-2.
14. A student is awarded Ex grade if he gets more than 90 marks. He is awarded A grade if marks are
between 80 and 89. Similarly range for B, C, D and P are 70-79, 60-69, 50-59, and 35-49
respectively. The student is awarded F grade if he gets less then 35 marks. Program reads marks of
a student and prints his grade.
15. No income tax is to be paid if income is less than 5000. If income is between 5000 and 6000 then
tax is 10% of the amount by which the income exceeds 5000. If income is between 6000 and 15000
then the tax is 100 + 20% of the amount by which the income exceeds 6000. If income is more than
15000 then the tax is 1900 + 30% of the amount by which the income exceeds 15000. E.g. if income
is 10000 then the tax will be 100 + (10000-6000)*20/100 = 900. Write a program, which reads
income and calculates the income tax.
16. Write a program, which reads a number X and prints a number Y. Y=X+10 if X is 6. Y is X*X if X
is 7. Y is 2*X+4 if X is 12. Otherwise Y is X*6-1. (use switch)
17. Write a program, which reads three integers X, Y and Z and prints Y+Z if X is 0. If X is 1 then Y-
Z is printed. If X is 2 then Y*Z is printed. If X is 3 then Y/Z is printed. (use switch

You might also like