Returns the root of the quadratic equation ax2 + bx + c = 0. The values of coefficients A (a = 0), B, and C are input by the keyboard.
Source: Internet
Author: User
// Obtain the root of the quadratic equation ax2 + bx + c = 0. The values of coefficients A (a = 0), B, and C are input by the keyboard.
# Include <iostream>
# Include <math. h>
Using namespace STD;
// Root
Float get_x (float a, float B, float C)
{
Float x1, x2, X;
If (B * B-4 * a * C <0)
{
Cout <"This equation has no solid roots! "<Endl;
}
Else if (0 = B * B-4 * a * C)
{
X = (-B)/2/;
Cout <"when the equation has two equal Real Roots: X1 = x2 =" <x <Endl;
}
Else
{
X = SQRT (B * B-4 * a * C );
X1 = (-B + x)/2/;
X2 = (-B-x)/2/;
Cout <"when the equation has two unequal Real Roots: X1 =" <X1 <"" <"X2 =" <X2 <Endl;
}
Return 0;
}
Void main ()
{
Float a, B, c;
Cout <"general equation: ax2 + bx + c = 0" <Endl;
Cout <"Enter the values of coefficients A, B, and C respectively (a = 0):" <Endl;
Cin> A> B> C;
Get_x (A, B, C );
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.