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("a: ");
- scanf("%f", &a);
- printf("b: ");
- scanf("%f", &b);
- printf("c: ");
- scanf("%f", &c);
- D = b*b - 4*a*c;
- if(fabs(D) < 0.001)
- {
- x1 = -b / (2 * a);
- printf("x1 = x2 = %.2f", x1);
- }
- else if(D > 0)
- {
- x1 = (-b + sqrt(D)) / (2 * a);
- x2 = (-b - sqrt(D)) / (2 * a);
- printf("x1: %.2f\n x2: %.2f", x1, x2);
- }
- else
- {
- printf("No real roots!");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment