Home > Back-end >  For a yuan quadratic equation root
For a yuan quadratic equation root

Time:02-16

This topic requires a yuan quadratic equation ax + bx + c ^ 2=0, the root of the reserve 2 decimal places,
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:

reference 1st floor rili1998 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);
}
}
not ah, or not

CodePudding user response:

Reference:
 # include 
# include
Int main ()
{
Double a, b, c, da;
Lf the scanf (" % % % lf lf ", & amp; A, & amp; B, & amp; C);
Da=b * * a * b - 4 c.
If (a!=0) {
If (da> 0 {
Printf (" % 2 lf \ n ", (a - b + SQRT (da))/(a * 2));
Printf (" % 2 lf \ n ", (a - b - SQRT (da))/(a * 2));
}
Else if (da & lt; 0 {
If (b!=0) {
Printf (" % % 2 lf +. 2 lfi \ n ", (b)/(2 * a) * 1.0, SQRT (da)/(2 * a));
Printf (" % % 2 lf +. 2 lfi \ n ", (b)/(2 * a) * 1.0, - SQRT (da)/(2 * a));
} else {
Printf (" % % 2 lf +. 2 lfi \ n ", 0.0, SQRT (da)/(2 * a) * 1.0);
Printf (" % % 2 lf +. 2 lfi \ n ", 0.0, - SQRT (da)/(2 * a) * 1.0);
}
}
The else {
Printf (" % 2 lf \ n ", - b * 1.0/(2 * a));
}
}
Else if (a==0 & amp; & B==0 & amp; & C==0) {
Printf (" Zero Equation \ n ");
}
Else if (a==0 & amp; & B==0 & amp; & c!=0) {
Printf (" Not An Equation \ n ");
}
Else if (a==0 & amp; & B!=0 & amp; & c!=0)
Printf (" % 2 lf \ n ", (1.0) - c */b);
system("pause");
return 0;
}
  • Related