/* * program to solve quadratic equation * prompts for three coefficients a, b, and c and prints real roots (if any) * of a*x*x + b*x + c = 0. */ #include #include int main(void) { float a, b, c; double r1, r2; printf("enter a b c\n"); if (scanf("%f %f %f", &a, &b, &c) != 3) { printf("not numbers\n"); return 1; } if (a != 0) { int discrim = b*b - 4*a*c; if (discrim < 0) { printf("no real roots\n"); } else { r1 = (-b + sqrt(discrim))/(2*a); r2 = (-b - sqrt(discrim))/(2*a); printf("%f %f\n", r1, r2); } } else if (b != 0) { printf("%f\n", -c/b); } else if (c != 0) { printf("no solution\n"); } else { printf("all x's are solutions\n"); } return 0; }