Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include "math.h"
- int main()
- {
- float a, b, c, d, x1, x2;
- printf("Input A, B, C for the quadratic equation Ax^2 + Bx + C = 0\n");
- printf("A = "); scanf("%f", &a);
- printf("B = "); scanf("%f", &b);
- printf("C = "); scanf("%f", &c);
- d=b*b-4*a*c;
- printf("d = %.2f\n", d);
- if (a==0) printf("The equation has exactly one root: x = %.2f", -c/b);
- else if (d<0)
- {
- x1=-b/(2*a);
- x2=sqrt(-d)/(2*a);
- printf("The equation has two distinct complex roots.\n");
- printf("x1 = %.2f + %.2fi\n", x1, x2);
- printf("x1 = %.2f - %.2fi", x1, x2);
- }
- else if (d==0)
- {
- printf("The equation has exactly one double root:\nx1 = x2 = %.2f", -b/(2*a));
- }
- else
- {
- x1=(-b+sqrt(d))/(2*a);
- x2=(-b-sqrt(d))/(2*a);
- printf("The equation has two distinct real roots.\nx1 = %.2f\nx2 = %.2f", x1, x2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement