/* * Program to find roots of quadratic equation. */ #include #include int main(void) { float a, b, c; printf("enter coefficients a, b, c:\n"); if (scanf("%f %f %f", &a, &b, &c) != 3) { /* FIXME improve this error message */ printf("error\n"); return 1; } printf("a = %f, b = %f, c = %f\n", a, b, c); /* FIXME there are some other cases to consider here! */ if ((b*b - 4*a*c) < 0) { printf("no real roots\n"); } else { printf("roots are %f and %f\n", (-b + sqrt(b*b - 4*a*c)) / (2*a), (-b - sqrt(b*b - 4*a*c)) / (2*a)); } return 0; }