/* File: quadratic.c Solve for two roots of the quadratic equation x^2-5x+6 = 0 */ #include #include /* for sqrt() */ int main() { /* declare variables for the coefficients of the quadratic equation and roots; initialize the coefficients */ double a = 1.0, b = -5.0, c = 6.0, x1, x2; /* solve for two roots of the quadratic equation */ x1 = (-b+sqrt(b*b-4*a*c))/(2*a); /* first branch */ x2 = (-b-sqrt(b*b-4*a*c))/(2*a); /* second branch */ /* display two roots */ printf("x1 = %f\n", x1); printf("x2 = %f\n", x2); return 0; }