You are on page 1of 23
PROGRAM TO SOLVE A QUADRATIC EQUATION (WITHOUT VALIDATION) #include #inelude finclude void main() float a,b,c.d; float rl.12; printf(’"Quadratic Equation: er the value of a :"); a); Snter the value of b :"); seanf("%4t",&b); print{("Enter the value of ¢ :"); scanfi"¥%t" 8c); d=btb- dtate; rl =(-btsqrt(d))/(2*a); 12 = (-b-sqrt(d)/(2*a); print{("The roots are : %f,%f".r1.12); getch() TEST CASES Teta | b |e Expected Output ‘Actual Output | Match? 1 =I | 50 | 50 | Values Outside Range No S (Ome sor |ers0) ‘Equation is not a No quadratic equation o 3 i [50 | 50 r1=-1.020842 Yes u 8.979156 + 30 | 50 | 50 | r1=-0.500000+i0.866025 No 11=-0.500000-i0.866025, 3 99 [350 | 50 | r1=0.252525+i0.664290 No 11=-0,252525-10.664290 € | 100 | 50 | 50 | rl=0.250000+i0.661438 No 11=-0,250000-i0.661438 7 101 50, 50, Values Outside Range No. 8 50, -l 50 Values Outside Range No. 9 | 30 | 0 | 50 | r1=-0.000000+i1.000000 No 11=-0,000000-i1.000000 10 | 50 | 1 | 50 | r1=-0.010000+i0.999950 No .010000-i0.999950 i | 30 | 99 | 50 | r1=-0.990000+i0.141067 No .990000-i0.141067 12 | 50 | 100 | 50 000000 Yes 000000 3 130 | 101 | 50 | Values Outside Range No 1.151775 + 50 | 50 | -1 | Values Outside Range 0.019615 No 12=1.019615 50 | 50] 0 000000 11=0.000000 | Yes 000000 % | 50 | 50] 1 .020417 Yes 12=-0.979583 17 | 50 | 30 | 99 | rl=0.500000+i1.315295 No -0.500000-i1 315295 18 | 50 | 30 | 100 | 1.322876 No 1.322876 19 | 50 | 50 | 101 | Values Outside Range No PROGRAM TO SOLVE A QUADRATIC EQUATION (WITH VALIDATION) =include ‘lude nclude void main() float a,b,¢,d,d1; float r1,12.i1 i2; elrser(): printf("Quadratic Equation: ax2+bx+c=0in"); printf("Enter the value of a :"); scant("%f",é&a); if a<0 | a>100) { printf("The value of a should be between 0 to 100\n"); getch(); exit(0); } printf("Enter the value of b:"); scanf("%f",&b); if( b <0 || b>100) { printf("The value of b should be between 0 to 100\n"); geteh(); exit(0); ) printf("Enter the value of ¢ :"); scani("%t",&c); if <0|| ¢>100) t printi("The value of c should be between 0 to 100\n"); getch(); exit(0); $ iffa=0) print{("Equation is not a quadratic equation\n"); else t d=b*b- 4*ate; dl = sqrt(abs(d)); il = -b/(2*a): i2=d1/(2*a); if(d<0) { printf("Imaginary Roots\n"); printf("The roots are Yef*i%f, %f-i%f\n" i i2,i1,i2); } else { if(d==0) print{("Roots are real and equal\n’ else printf("Roots are real and distinet\n"); rl =il +i2; 12=i1-i2; print{("The roots are : %f,%f",r1.12); 3 } getch(); TEST CASES DY] aloe Expected Output ‘Actual Output Mat | ch? 1_[--1 [30 [50 | Values Outside Range | Values Outside Range | Yes 21 0 | 50 | 50 Equation is not a Equation is not a Yes | = - __ | quadratic equation _| __quadratic equation, 3} 1 [30 | 30 1.020842 1.020842 Yes 8.979156 48,979156 -0.500000+i0.866025 | r1=-0.500000+i0.866025 | Yes r1=-0.500000-i0.86602: 11=-0.500000-10.866025_| 50. | r1=-0.2525254+40.664290 | 11 ! 11=-0,252525-i0,66429 0.250000+0.661438 .250000+i0.661438 | Yes 11=-0,250000-i0,661438 | r1=-0.250000-i0,661438 30_| Values Outside Range | Values Outside Range | Yes '50_| Values Outside Range | Values Outside Range | Yes 50 -0.000000+i 1.000000 | r1=-0.000000+i1.000000 | Yes r1=-0,000000-i1,000000 | r1=-0.000000-i1.000000 11=-0.010000+i0.999950 | Yes r1=-0.010000-i0.999950 | rl=-0.010000-i0.999950 11 | 50 | 99 | 50 | r1=-0.990000+i0.141067 | r1=-0.990000+i0.141067 | Yes r1=-0,990000-i0,141067 | _r1=-0,990000-i0.141067 | 10 | 50] 1 | 50 12 | 50 | 100 | 50 r1=-1.000000 r1=-1,000000 Yes _ r2=-1.000000 ___12=.1,000000 13 [50 Values Outside Range | Values Outside Range | Yes —14 [50 Values Outside Range | Values Outside Range _| Yes 15 | 50 ¥1=0.000000 11=0.000000 Yes Lt 1.000000 1.000000 16 0.020417 0.020417 Yes 12=-0.979583 12=-0,979583 17 | 50 | 50 | 99 | r1=-0.500000+i1.315295 | r1=-0.500000+i1.315295 | No r1=-0,500000-i1.315295 | r1=-0,500000-i1.315295 322876 | r1=-0.500000+i1.322876 | No | r1=-0,500000-i1.322876 Values Outside Range | No 50 | 100 50 | 101 | Values Outside Range TEST CASES ID] a b © Expected Output ‘Actual Output Mat i ch? 1p 50 | 50 | Values Outside Range Values Outside Range | Yes 2 oO 50, 50, Equation is not a Equation is not a Yes quadratic equation quadratic equation 3 1 50 50 ri=-1.020842 r1=-1.020842 Yes 12=-48.979156 12=48.979156 4+) 30 | 50 | 50 '500000+i0.866025 | r1=-0.500000+i0.866025 | Yes | -0.500000-10.866025 ).500000-10.866025 7 99 | 50 | 50 .252525+10.664290 | 11=-0.252525-+i0.664290 | Yes | 0.252525-i0.664290 | _r1=-0.252525-i0.664290 6 | 100 | 50 | 50 ).250000+10.661438 .250000+i0.661438 | Yes | -0.250000-i0.661438 250000-i0.661438 7/101 | 50 [ 50 |” Values Outside Range | Values Outside Range | Yes a_| 50 | -1 [50 | Values Outside Range | Values Outside Range | Yes 9 | 50 0 50 000000+i1.000000 | r1=-0.000000+i1.000000 | Yes ! 0.000000-i1.000000 0.000000-i1,000000 10; 30 | 1 | 50 .01000040.999950 .010000i0.999950 | Yes | -0.010000-i0.999950 -0.010000-i0.999950 ies fase noo so) .990000+i0.141067 .990000i0.141067 | Yes ! -0.990000-i0.141067 -0.990000-i0.141067 12 50 | 100 | 50 1.000000 1.000000 Yes 1.000000 1.000000 1350 | 101 | 50 | Values Outside Range ‘Values Outside Range | Yes 14 50 | 50 | -1 ‘Values Outside Range Values Outside Range | Yes is 50 | so] 0 11=0.000000 Yes 16 50 | 50 | 1 Yes 12=-0.979583 i7geaes0is sO 09 .500000+i1.315295 No -0.500000-i1.315295_| r1=-0.500000-i1.315295 18 | 50 | 50 | too .500000+i1.322876 | r1=-0.5000004i1 322876 | No | ).500000-i1.322876 0,500000-i1.322876 19 | 50 | 50 | 101 | Values Outside Range | Values Outside Range | No PROGRAM TO SOLVE TRI- YGLE PROBLEM (WITHOUT VALIDATION ) #include #inelude #include void main() t int x,y.25, clrser(); printf("Enter the value of the three sides : \n"); printf("X ="); seanfi("%d" Sx); printi(’\n :"); scanf("%d",&y); printf("\nz. :"): scanf("%d",8&z); if ((xty > 2) && (ytz> x) && (z+x> y)) { if (—y && y=2) printf(’\nThis ia an Equilateral triangle"); else if (x==y || y==z || z==x) print{("\nThis is an Isoceles triangle"); else printf("\nScalene Triangle"); if (xtxtyty—2"2 || ytytz*z==x*x || ztzbxtx=ayty) printi("\nRight Angled Triangle"); } else printf(""\nNot a triangle"); geteh(); TEST CASES mw) xXi]yY iz Expected Output ‘Actual Output i | 0 | 50 | 50 | Values Outside Range Not ad 2) 1 {| 30 [30 Isosceles A Isosceles A | ent 508 2850) Isosceles A Isosceles A + | 50 | 50 | 30 Equilateral Equilateral 8 Yes a Tsosceles A Isosceles A ‘Yes 6 | 100 | 50 | 50 Nota A Not aA Yes 7 | 101 | so | 50 |” Values Outside Range Nota A No 8/50 | 0 | 50 | Values Outside Range NotaA No Ce Tsosceles A Tsosceles A ‘Yes 10 | 50 [| 2 | 50 Isosceles A Isosceles A ‘Yes u{ so [99 | s0 Tsosceles A Tsosceles A Yes 12 | 50 | 100 | 50 Nota Nota A Yes 13 | 50 | 101 | 50 |” Values Outside Range Nota A No 14 | 50 | 50 [0 | Values Outside Range Nota No 15 [50 [50 [1 Isosceles A Tsosceles A Yes 16 | so | so | 2 Isosceles A Isosceles A Yes 17 [50 [50 [99 [| Isosceles A Isosceles A Yes 18 | 50 [so [100 Nota NotaA Yes 19 {50 | 50 | 101 | Values Outside Range NotaA No PROGRAM 10 SOLVE TRIANGLE PROBLEM. (WITH VALIDATION ) include nclude #inelude void main) int x,y,z; elrser(); printf("Enter the value of the three sides : \n"); printf("X :"); scanf("%d",&x); printf("\nY ="); scani("%d",&y); printf("\nZ. :"); seanfi"%d",&z); if ((x<1 || x >100) | (y100) fl (z100)) printf(""\nValues outside range"); else if (x+y > 2) && (ytz > x) && (24x > y)) t if (X==y && y==2) printf("\nThis ia an Equilateral triangle"); else if (xy ll y==z || z=y) printf("\nThis is an Isoceles triangle"); else printf” if (x*xty*y= printf(” Scalene Triangle"); 242 || ytytatz==x*x || 2424x4x- Right Angled Triangle"); 3 else printf("\nNot a triangle"); getch();

You might also like