//If a, b and c are all zero, then every value of x is a real root.
if(a == 0 && b == 0 && c == 0)
{
real_root = 3;
}
//If a and b are zero and c is non-zero, then there are no real roots.
if(a == 0 && b == 0 && c != 0)
{
real_root = 0;
}
//If a is zero and b is non-zero, then the only real root is x = -c/b.
if(a == 0 && b != 0)
{
real_root = 1;
}
//If a is non-zero and b^2 < 4ac, then there are no real roots.
if(a != 0 && b*b < (4*a*c))
{
real_root = 0;
}
//If a is non-zero and b^2 = 4ac, then there is one real root x = -b/2a.
if(a != 0 && b*b == (4*a*c))
{
real_root = 1;
}
//If a is non-zero and b2 > 4ac, then there are two real roots.
if(a != 0 && b*b > (4*a*c))
{
real_root = 2;
}
cout << "The number of real roots is: " << real_root << endl;
//If a, b and c are all zero, then every value of x is a real root.
if(a == 0 && b == 0 && c == 0)
{
x1 = 0;
x2 = 0;
cout << "The real roots are:" "\n";
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << "\n";
}
//If a and b are zero and c is non-zero, then there are no real roots.
if(a == 0 && b == 0 && c != 0)
{
cout << "There are no real roots" "\n";
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << "\n";
}
//If a is zero and b is non-zero, then the only real root is x = -c/b.
if(a == 0 && b != 0)
{
x1 = -c/b;
x2 = 0.0;
cout << "The only real root is" "\n";
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << "\n";
}
//If a is non-zero and b^2 < 4ac, then there are no real roots.
if(a != 0 && b*b < (4*a*c))
{
cout << "There are no real roots" "\n";
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << "\n";
}
//If a is non-zero and b^2 = 4ac, then there is one real root x = -b/2a.
if(a != 0 && b*b == (4*a*c))
{
x1 = -b/2*a;
x2 = 0.0;
cout << "There is one real root:" "\n";
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << "\n";
}
//If a is non-zero and b2 > 4ac, then there are two real roots.
if(a != 0 && b*b > (4*a*c))
{
x1 = (-b + (sqrt(pow(b,2)-(4*a*c))))/(2*a);
x2 = (-b - (sqrt(pow(b,2)-(4*a*c))))/(2*a);
cout << "The real roots are:" "\n";
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << "\n";
}