cout << "Program computer and priants real roots \n of a quadratic polynomial: a*x^2 + b*x + c";
cout << "Enter three numbers a, b, and c, separated by spaces" << endl;
cin >> a >> b >> c;
if (a == 0)
if (b == 0)
if(c == 0)
cout << "Degenerate case" << endl;
else
cout << "Inconsistent " << c << endl;
else
{
root = - (c / b);
cout << "Linear case is " << root << endl;
}
else
{
cout << "The quadratic equation " << a << "*x^2 + " << b << "*x + " << c;
discrim = ((b * b) - (4.0 * a * c));
}
if (a != 0)
if (b != 0)
if (c != 0)
if (discrim > 0)
{
root1 = ((- b + sqrt((b * b) - (4.0 * a * c)) / ((2 * a))));
root2 = ((- b - sqrt((b * b) - (4.0 * a * c)) / ((2 * a))));
cout << " has two real roots: " << endl;
cout << "root1 = " << root1 << " and root2 = " << root2 << endl;
}
else
if (discrim == 0) //same for the first two lines
{
root1 = ((- b + sqrt((b * b) - (4.0 * a * c)) / ((2 * a))));
root2 = ((- b - sqrt((b * b) - (4.0 * a * c)) / ((2 * a))));
cout << " has two of the same roots: " << endl;
cout << "root1 = root2 = " << root2 << endl;
}
else
if (discrim < 0)
{
cout << " has complex roots." << endl;
}