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("Enter 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);
- if (a==0)
- {
- x1=-c/b;
- printf("\nThe equation has one root.\nx = %.3f", x1);
- }
- else
- {
- d=b*b-4*a*c;
- if (d<0)
- {
- x1=-b/(2*a);
- x2=(sqrt(-d))/(2*a);
- printf("\nThe equation has two distinct complex roots.\n");
- printf("x1 = %.3f + %.3fi\n", x1, x2);
- printf("x2 = %.3f - %.3fi", x1, x2);
- }
- else if (d==0)
- {
- x1=-b/(2*a);
- printf("\nThe equation has exactly one real root.\nx = %.3f", x1);
- }
- else
- {
- x1=(-b+sqrt(d))/(2*a);
- x2=(-b-sqrt(d))/(2*a);
- printf("\nThe equation has two distinct real roots.\n");
- printf("x1 = %.3f\n", x1);
- printf("x2 = %.3f", x2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement