C language: Calculate the heel of the quadratic equation of a. The coefficients a, B, and c are input by the keyboard.
Calculate the following of the quadratic equation of a, B, and c from the keyboard input program:
# Include <stdio. h> # include <math. h> int main () {double a, B, c, d, p, q, x1, x2; printf ("Enter the value of a, B, c :"); scanf ("% lf", & a, & B, & c); d = B * B-4 * a * c; if (d> = 0) {p =-B/(2.0 * a); q = sqrt (d)/(2.0 * a); x1 = p + q; x2 = p-q; printf ("x1 = % lf \ nx2 = % lf \ n", x1, x2 ); // use lf to output the decimal part with 6 digits/* printf ("x1 = % 7.2f \ nx2 = % 7.2f \ n", x1, x2 ); * // The specified output data occupies 7 columns and the decimal number occupies 2} else {printf ("the original equation has no real number solution \ n");} return 0 ;}
Result: Enter the values of a, B, and c: 2 3 1x1 =-0.500000x2 =-1.000000. Press any key to continue...