Question: Question. How many boolean expressions are specified? int main() { double a, b, c, disc, root1, root2; cout < < This program calculates the roots

Question. How many boolean expressions are specified?

int main()

{ double a, b, c, disc, root1, root2;

cout << "This program calculates the roots of a ";

cout << " quadratic equation of the form ";

cout << " 2 ";

cout << " ax + bx + c = 0 ";

cout << "Please enter values for a, b, and c: ";

cin >> a >> b >> c;

if ( a == 0.0 && b == 0.0)

cout << "The equation is degenerate and has no roots. ";

else if (a == 0.0)

cout << "The equation has the single root x = "

<< -c/b << endl;

else

{

disc = pow(b,2.0) - 4 * a * c; // calculate discriminant

if (disc > 0.0)

{

disc = sqrt(disc);

root1 = (-b + disc) / (2 * a);

root2 = (-b - disc) / (2 * a);

cout << "The two real roots are "

<< root1 << " and " << root2 << endl;

}

else if (disc < 0.0)

cout << "Both roots are imaginary. ";

else

cout << "Both roots are equal to " << -b / (2 * a) << endl;

}

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!