/* * Program to find real roots of quadratic equation. */ #include #include int main(void) { printf("enter coefficients a, b, c\n"); double a, b, c; if (scanf("%lf %lf %lf", &a, &b, &c) != 3) { printf("invalid input\n"); return 1; /* bail out of program */ } double d = b*b - 4*a*c; if (d < 0) { printf("no real roots\n"); return 0; } if (a != 0) { double r1 = (-b + sqrt(d))/(2*a); double r2 = (-b - sqrt(d))/(2*a); printf("roots for a = %f, b = %f, c = %f are %f, %f\n", a, b, c, r1, r2); } else if (b != 0) { double r1 = -c / b; printf("root for a = %f, b = %f, c = %f is %f\n", a, b, c, r1); } else { if (c != 0) { printf("no solutions\n"); } else { printf("infinitely many solutions\n"); } } return 0; }