Write a C Code to calculate D = π^π β πππ and show the result according to following conditions:
a. D>0 then Calculate X1, X2. Where ππ = (βπ+βπ^πβπππ)/ππ and ππ = (βπββπ^πβπππ)/ππ
b. D =0 then calculate X. Where π± = π^π/ππ
c. D<0 then print βNo Solutionβ.
Sample Input
Enter a, b & c: 5 6 1
Sample Output
X1: -0.2
X2: -1
Sample Output
Enter a, b, & c: 5 6 1 X1: -0.200 x2: -1.000
Source Code
#include<stdio.h> #include<math.h> int main() { float D, b, a, c, x, x1, x2; printf("Enter a, b, & c: "); scanf("%f %f %f", &a, &b, &c); D = ((b*b) - 4*a*c); if(D > 0) { x1 = (-b + sqrt(D))/(2*a); x2 = (-b - sqrt(D))/(2*a); printf("X1: %.3f\nx2: %.3f\n\n", x1, x2); } else if(D == 0) { x = (b*b)/(2*a); printf("X: %f\n\n"); } else if(D < 0) { printf("No Solution\n\n"); } return 0; }
Sample Output
Enter a, b, & c: 5 6 1 X1: -0.200 x2: -1.000
No comments:
Post a Comment