-->
当前位置:首页 > 题库

PROGRAMMING:Solving quadratic equation of one variable

Luz5年前 (2021-05-10)题库567
Solving quadratic equation of one variable
Please write a program to solve the unary linear equation $$a x ^ 2 + B x + C = 0 $$.
The root formula of quadratic equation of one variable is as follows:
![ Title. JPG] (~ / 2b51fa83-bfaf-4c88-87c8-5776fa4497a6. JPG)
requirement:
-If $$a = 0 $$, it is a linear equation of one variable.
-If $$B / NEQ 0 $$, then the equation has a unique solution, and the solution is output;
-If $$B = 0, C / NEQ 0 $$, then the equation has no solution and "no solution" is output;
-If $$B = 0, C = 0 $$, the equation has infinitely many solutions and outputs "infinitely many solutions".
-If $$a / NEQ 0 $$, it is a quadratic equation with one variable.
-If $$\ delta > 0 $$, then the equation has two unequal real roots and outputs the two roots;
-If $$\ delta = 0 $$, then the equation has two equal real roots and outputs the two roots;
-If $$\ delta < 0 $$, then the equation has two conjugate imaginary roots and outputs the two roots.
####Input format
> $$a, b, c$$
####Output format
>$$x $$or $$X_ 1, x_ 2$$
Note: all real numbers output 6 significant digits, and do not output meaningless 0 and decimal point at the end.
####Input sample 1
```in
0 4.5 -3.6
```
####Output sample 1
```out
x = 0.8
```
####Input sample 2
```in
0 2.8 0
```
####Output sample 2
```out
x = 0
```
####Input sample 3
```in
0 0 3.6
```
####Output sample 3
```out
unsolvable
```
####Input sample 4
```in
0 0 0
```
####Output sample 4
```out
Infinitely many solutions
```
####Input sample 5
```in
-2 0.8 -0.06
```
####Output sample 5
```out
x1 = 0.1, x2 = 0.3
```
####Input sample 6
```in
-1 0.2 0
```
####Output sample 6
```out
x1 = 0, x2 = 0.2
```
####Input sample 7
```in
1 -0.4 0.04
```
####Output sample 7
```out
x1 = x2 = 0.2
```
####Input sample 8
```in
0.3 0 0
```
####Output sample 8
```out
x1 = x2 = 0
```
####Input sample 9
```in
-0.2 0.04 -0.01
```
####Output sample 9
```out
x1 = 0.1-0.2i, x2 = 0.1+0.2i
```
####Input sample 10
```in
3 0 0.27
```
####Output sample 10
```out
x1 = 0+0.3i, x2 = 0-0.3i
```
Tip: pay attention to the problem of negative zero and error of real number.
---
Related exercises: solving linear equation with one variable







answer:If there is no answer, please comment