Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- void main()
- {
- float a, b, c, d;
- printf("Enter a b and c co-effecients for equation of the form a*x^2 + b*x + c = 0\n");
- scanf("%f %f %f", &a, &b, &c);
- if (a == 0)
- printf("The Equation is not Quadratic!\n");
- else
- {
- d = pow(b, 2) - (4 * a*c);
- if (d < 0)
- {
- printf("Imaginary Roots\n");
- d = sqrt(-d);
- printf("Roots:\nX1 = %.2f + i%.2f\nX2 = %.2f - i%.2f\n", -b / (2 * a), d / (2 * a), -b / (2 * a), d / (2 * a));
- }
- else
- {
- d = sqrt(d);
- if (d == 0)
- {
- printf("Roots are equal\n");
- printf("Roots:\nX = %.2f\n", -b / (2 * a));
- }
- else
- {
- printf("Roots are unequal\n");
- printf("Roots:\nX1 = %.2f\nX2 = %.2f\n", (-b + d) / (2 * a), (-b - d) / (2 * a));
- }
- }
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement