A middle school student asked me how to find the root of the quadratic equation of one yuan over the past few days. I was so stupid that I didn't know where to start. At that time, I remember that I could never remember the formula, during the examination, it took a lot of time to calculate the formula. The formula calculated from the results is often less than the plus or minus sign. Calculate the formula again this time,
As a result, the student said that this formula was very familiar and found it in the book. I was hit by BS ........
It's boring to write and write code to pass the time. I simply wrote the code to my blog. I wrote a program to show it to him. The classmate said it was very convenient and he also said that the program was doing a very fast job on the subject. It can be used during the exam, saving a lot of time. Khan .....
I did not hurt him. I must take it back.
Common form of quadratic equation: ax ^ 2 + bx + c = 0, (a =0)
The basic idea of solving a quadratic equation is to convert it into two one-dimensional equations by downgrading.
There are four solutions to the quadratic equation of one element: 1. Kaiping method; 2. formula method; 3. formula method; 4. factorization method.
I will not talk about the specific solution, but directly go to the Code:
# Include <iostream. h>
# Include <math. h>
Int solution (double paraA, double paraB, double paraC, double & x1, double & x2)
{
// Delta = b2-4ac
Int count;
Double delta = paraB * paraB-4 * paraA * paraC;
If (delta> 0) // has two solutions
{
// Calculate the solution based on the binary one-time Solution Formula
X1 = (-paraB) + sqrt (delta)/2 * paraA;
X2 = (-paraB)-sqrt (delta)/2 * paraA;
Count = 2;
}
Else if (delta = 0)
{
// Calculate the solution based on the binary one-time Solution Formula
X1 = (-paraB)/2 * paraA;
Count = 1;
}
Else
{
Count = 0;
}
Return count;
}
Int main ()
{
Double a, B, c;
Double x, y;
Cout <"Enter three parameters of the binary one-time equation (ax2 + bx + c)" <endl;
Cin>;
Cin> B;
Cin> c;
Cout <"a =" <a <", B =" <B <", c =" <c <endl;
Int count = solution (a, B, c, x, y );
If (count = 0)
{
Cout <"no solution to this equation" <endl;
}
Else if (count = 1)
{
Cout <"This equation has a solution: x1 =" <x <endl;
}
Else if (count = 2)
{
Cout <"This equation has two solutions: x1 =" <x <"; x2 =" <y <endl;
}
Else
{
Cout <"this equation is abnormal" <endl;
}
Return 1;
}
This is basically the case! Happy weekend!