PROGRAMMING:Chen Kun's solution to quadratic equation of one variable
###Task description
Mr. Yu quoted a question from a teacher of Zhejiang University in PTA
![ Untitled. PNG] (~ / 09b1eda7-0fe9-4dba-b03b-ed0a6ac47fba. PNG)
```
Finding the root of quadratic equation of one variable
This topic requires the root of quadratic equation of one variable, and the result retains 2 decimal places.
Input format:
The input gives three floating-point coefficients a, B and C in one line, separated by spaces.
Output format:
According to the coefficient, different results are output
1) If the equation has two unequal real roots, each line outputs one root, which is larger first and smaller later;
2) If the equation has two unequal complex roots, each line outputs a root according to the format of "real part + imaginary part I". The imaginary part is positive first, and then negative;
3) If the equation has only one root, the root is directly output;
4) If the coefficients are all 0, "zero equation" is output;
5) If a and B are 0 and C is not 0, "not an equation" is output.
```
```
Chen Kun submitted the following code according to the conventional solution, which was unsuccessful:
#include
#include
int main(){
double a,b,c,deta;
scanf("%lf%lf%lf",&a,&b,&c); // input data
deta=b*b-4*a*c; // Calculate Delta
if(a==0&&b==0&&c!= 0) {/ / 1. Nonequation
printf("Not An Equation");
}
Else if (a = = 0 & & B = = 0 & & C = = 0) {/ / 2.0 equation (0 equation)
printf("Zero Equation");
}
else if(a==0&&b!= 0) {/ / 3. First order equation
printf("%.2f",-c/b);
}
Quadratic equation
If (deta = = 0) {/ / 4.1 has two equal real roots
printf("%.2f", (-b)/(2*a) );
}
There are two unequal real roots in else if (deta > 0) {/ / 4.2
printf("%.2f\n",(-b)/(2*a)+sqrt(deta)/(2*a));
printf("%.2f", (-b)/(2*a)-sqrt(deta)/(2*a));
}
There are two complex roots in else {/ / 4.3
printf("%.2f+%.2fi\n",(-b)/(2*a),sqrt(-deta)/(2*a));
printf("%.2f-%.2fi", (-b)/(2*a),sqrt(-deta)/(2*a));
}
}
return 0;
}
Later, teacher Yu found that the original question was not very strict and needed to be supplemented as follows:
```
###Input format:
```
The input format is shown in the figure, and there is no supplement. Still: give three floating-point numbers a, B, C in a row, separated by spaces.
```
###Output format:
```
(1) When two real roots are required to be output in the original question, the first is big and then small. The original question test data does not design this requirement, which leads to the output of the first is small and then big also passed.
(2) In addition, it should be noted that when outputting the root or real part of the value 0, do not output -0.00, but if you output 0.00, otherwise you can't improve the traffic.
In view of the above two points, the input and output samples 6, 7 and 8 are designed by Yu, as well as the corresponding test data.
Combined with the above instructions, please solve the problem according to the original output format.
```
###Input sample 1:
```
2.1 8.9 3.5
```
###Output sample 1:
```
-0.44
-3.80
```
###Input sample 2:
```
1 2 3
```
###Output sample 2:
```
-1.00+1.41i
-1.00-1.41i
```
###Input sample 3:
```
0 2 4
```
###Output sample 3:
```
-2.00
```
###Input sample 4:
```
0 0 0
```
###Output sample 4:
```
Zero Equation
```
###Input sample 5:
```
0 0 1
```
###Output sample 5:
```
Not An Equation
```
###Input sample 6 (supplemented by teacher Yu, test 0 pieces)
```in
5 0 0
```
###Output sample 6:
```out
zero
```
###Input sample 7 (added by Yu, the test starts from big and then small)
```in
-1 3 -2
```
###Output sample 7:
```out
two
one
```
###Input sample 8 (supplemented by teacher Yu, test 0 real part)
```in
1 0 1
```
###Output sample 8:
```out
0.00+1.00i
0.00-1.00i
```
###Input sample 9 (added by Yu, test output + imaginary part first, output - imaginary part later)
```in
-5 1 -6
```
###Output sample 9
```out
0.10+1.09i
0.10-1.09i
```
answer:If there is no answer, please comment
Mr. Yu quoted a question from a teacher of Zhejiang University in PTA
![ Untitled. PNG] (~ / 09b1eda7-0fe9-4dba-b03b-ed0a6ac47fba. PNG)
```
Finding the root of quadratic equation of one variable
This topic requires the root of quadratic equation of one variable, and the result retains 2 decimal places.
Input format:
The input gives three floating-point coefficients a, B and C in one line, separated by spaces.
Output format:
According to the coefficient, different results are output
1) If the equation has two unequal real roots, each line outputs one root, which is larger first and smaller later;
2) If the equation has two unequal complex roots, each line outputs a root according to the format of "real part + imaginary part I". The imaginary part is positive first, and then negative;
3) If the equation has only one root, the root is directly output;
4) If the coefficients are all 0, "zero equation" is output;
5) If a and B are 0 and C is not 0, "not an equation" is output.
```
```
Chen Kun submitted the following code according to the conventional solution, which was unsuccessful:
#include
#include
int main(){
double a,b,c,deta;
scanf("%lf%lf%lf",&a,&b,&c); // input data
deta=b*b-4*a*c; // Calculate Delta
if(a==0&&b==0&&c!= 0) {/ / 1. Nonequation
printf("Not An Equation");
}
Else if (a = = 0 & & B = = 0 & & C = = 0) {/ / 2.0 equation (0 equation)
printf("Zero Equation");
}
else if(a==0&&b!= 0) {/ / 3. First order equation
printf("%.2f",-c/b);
}
Quadratic equation
If (deta = = 0) {/ / 4.1 has two equal real roots
printf("%.2f", (-b)/(2*a) );
}
There are two unequal real roots in else if (deta > 0) {/ / 4.2
printf("%.2f\n",(-b)/(2*a)+sqrt(deta)/(2*a));
printf("%.2f", (-b)/(2*a)-sqrt(deta)/(2*a));
}
There are two complex roots in else {/ / 4.3
printf("%.2f+%.2fi\n",(-b)/(2*a),sqrt(-deta)/(2*a));
printf("%.2f-%.2fi", (-b)/(2*a),sqrt(-deta)/(2*a));
}
}
return 0;
}
Later, teacher Yu found that the original question was not very strict and needed to be supplemented as follows:
```
###Input format:
```
The input format is shown in the figure, and there is no supplement. Still: give three floating-point numbers a, B, C in a row, separated by spaces.
```
###Output format:
```
(1) When two real roots are required to be output in the original question, the first is big and then small. The original question test data does not design this requirement, which leads to the output of the first is small and then big also passed.
(2) In addition, it should be noted that when outputting the root or real part of the value 0, do not output -0.00, but if you output 0.00, otherwise you can't improve the traffic.
In view of the above two points, the input and output samples 6, 7 and 8 are designed by Yu, as well as the corresponding test data.
Combined with the above instructions, please solve the problem according to the original output format.
```
###Input sample 1:
```
2.1 8.9 3.5
```
###Output sample 1:
```
-0.44
-3.80
```
###Input sample 2:
```
1 2 3
```
###Output sample 2:
```
-1.00+1.41i
-1.00-1.41i
```
###Input sample 3:
```
0 2 4
```
###Output sample 3:
```
-2.00
```
###Input sample 4:
```
0 0 0
```
###Output sample 4:
```
Zero Equation
```
###Input sample 5:
```
0 0 1
```
###Output sample 5:
```
Not An Equation
```
###Input sample 6 (supplemented by teacher Yu, test 0 pieces)
```in
5 0 0
```
###Output sample 6:
```out
zero
```
###Input sample 7 (added by Yu, the test starts from big and then small)
```in
-1 3 -2
```
###Output sample 7:
```out
two
one
```
###Input sample 8 (supplemented by teacher Yu, test 0 real part)
```in
1 0 1
```
###Output sample 8:
```out
0.00+1.00i
0.00-1.00i
```
###Input sample 9 (added by Yu, test output + imaginary part first, output - imaginary part later)
```in
-5 1 -6
```
###Output sample 9
```out
0.10+1.09i
0.10-1.09i
```
answer:If there is no answer, please comment