Using formula X1 = (-B + SQRT (B * B-4 * a * C)/(2 * ), x2 = (-B-SQRT (B * B-4 * a * C)/(2 * A) returns the root of the quadratic equation ax2 + bx + c = 0, A is not equal to 0.
There are two main points to note in this question: 1. To understand the calculation of the complex number, we need to consolidate the virtual number to be learned in high school; 2. It is the limit hypothesis for the double value.
AC code:
1 # include <stdio. h> 2 # include <math. h> 3 4 int main () 5 {6 int N; 7 scanf ("% d", & N); 8 while (n --) 9 {10 double A, B, c; 11 double x1, x2; 12 scanf ("% lf", & A, & B, & C ); 13 Double Delta = B * B-4 * a * C; 14 if (delta> 0) 15 {16x1 = (-B + SQRT (DELTA )) /(2 * A); 17x2 = (-B-SQRT (DELTA)/(2 * A); 18 printf ("X1 = %. 5lf; x2 = %. 5lf \ n ", x1, x2); 19} 20 else if (FABS (DELTA) <1e-8) // when the absolute value of the double variable is extremely small, when it is smaller than the precision range, we think it is zero 21 {22x1 =-B/(2 * A); 23 printf ("X1 = x2 = %. 5lf \ n ", X1); 24} 25 else26 {27 Delta = 0-delta; // calculate the negative Delta value by 28 Double P =-B/(2 * A); 29 double Q = SQRT (DELTA)/(2 * ); 30 if (FABS (p) <1e-8) P = 0.0; // for negative zero detection 31 printf ("X1 = %. 5lf + %. 5lfi; x2 = %. 5lf-%. 5lfi \ n ", p, q, p, q); 32} 33} 34 return 0; 35}