/* * Example of using C library functions * * Compute two roots of the quadratic equation * a x^2 + b x + c = 0 when discriminant > 0 * Hanly and Koffman, Example 3.2, page 110 * */ #include #include int main(void) { double a, b, c; double disc, root_1, root_2; printf("Input the coefficients of the quadratic equation a, b, c > "); scanf("%lf%lf%lf",&a,&b,&c); printf("coefficients a = %.2f, b = %.2f, c = %.2f\n",a,b,c); /* compute two roots for discriminant > 0 */ disc = pow(b,2) - 4 * a * c; root_1 = (-b + sqrt(disc)) / (2 * a); root_2 = (-b - sqrt(disc)) / (2 * a); printf("disc = %.2f\n",disc); printf("root_1 = %.2f, root_2 = %.2f",root_1,root_2); return (0); }