Input format:
Coefficient of input given in a line of three floating point a, b, c, separated by Spaces in the middle,
The output format:
According to the coefficient of situation, the output of different results:
1) if the equation has two real root is not equal, the line output a root, after the first big small;
2) if there are two unequal plural root equation, is each line according to the format of "real + imaginary part I" output a root, output in the imaginary part of the first, after the output with negative imaginary part;
3) if there is only one equation root, then the output directly the root;
4) if the coefficient is Zero, the output "Zero Equation";
5) if a and b is 0, c is Not 0, then output "Not An Equation,"
# include
# include
Int main () {
Double a, b, c, da, s, t;
Lf the scanf (" % % % lf lf ", & amp; A, & amp; B, & amp; C);
Da=b * * a * b - 4 c.
If (a==0 & amp; & B==0 & amp; & C==0)
Printf (" Zero Equation ");
Else if (a==0 & amp; & B==0 & amp; & c!=0)
Printf (" Not An Equation ");
Else if (da==0)
Printf (" % 2 "lf, -/2 b/a);
Else if (a==0)
Printf (" % 2 "lf - c/b);
Else if (da> 0)
Printf (" % 2 lf \ n % 2 lf ", (a - b + SQRT (da))/2/a, (a - b - SQRT (da))/2/a);
Else if (da<0 {
S=b/(2 * a);
T=SQRT (da)/(2 * a);
Printf (" %. Lf + % 2. 2 lfi \ n % 2 lf - %. 2 lfi ", s, t, s, t);
}
}
There is a test point on the PTA (equation has a pure virtual root) before, help to see how to change
CodePudding user response:
When da is less than zero, if b=0, equation of real component is zero, all only explicit imaginary part line,
Else if (da<0 {
If (b!=0)
{
S=b/(2 * a);
T=SQRT (da)/(2 * a);
Printf (" %. Lf + % 2. 2 lfi \ n % 2 lf - %. 2 lfi ", s, t, s, t);
}
The else
{
T=SQRT (c/a);
Printf (" % 2 lfi \ n - % 2 lfi ", t, t);
}
}
CodePudding user response: