/* * Program to compute and print real roots of a*x**2 + b*x + c = 0 * (** denotes exponentiation) */ #include #include int main(void) { printf("enter three coefficients\n"); double a, b, c; double root1, root2; if (scanf("%lf %lf %lf", &a, &b, &c) != 3) { printf("need three numbers\n"); } else if (a == 0) { if (b == 0) { if (c != 0) { printf("no roots\n"); } else { printf("all x's are roots\n"); } } else { printf("one root %f\n", -c/b); } } else { double d = b*b - 4*a*c; if (d < 0) { printf("no real roots\n"); } else { root1 = (-b + sqrt(d)) / (2*a); root2 = (-b - sqrt(d)) / (2*a); printf("roots are %f, %f\n", root1, root2); } } return 0; }