Homework4 - HW #4 1. #include <iostream> #include...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
HW #4
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1. #include <iostream> #include <cmath> using namespace std; int main() { char l = 'y'; double a,b,c; while (l == 'y') { cout << "Please enter coefficient a: "; cin >> a; cout << "\nPlease enter coefficient b: "; cin >> b; cout << "\nPlease enter coefficient c: "; cin >> c; cout << "\n"; double z = (b*b-4*a*c); double x,y,j,k; if ((b*b-4*a*c) > 0) { x = (-b+sqrt(z))/(2*a); y = (-b-sqrt(z))/(2*a); cout << "The solutions to this quadratic equation are distinct and real:\n"; cout << "x1 = " << x << " and x2 = " << y << "\n\n";
Background image of page 2
else if ((b*b-4*a*c) < 0) { x = (-b/(2*a)); j = (sqrt(fabs(b*b-4*a*c)))/(2*a); y = (-b/(2*a)); k = (sqrt(fabs(b*b-4*a*c)))/(2*a); cout << "The solutions to this quadratic equation are distinct and complex:\n"; cout << "x1 = " << x << " + i*" << j << " and x2 = " << y << " - i*" << k<< "\n\n"; } else if ((b*b-4*a*c) == 0) { x = (-b/(2*a)); cout << "The solutions to this quadratic equation are identical and real:\n\n"; cout << "x1 = x2 = " << x << "\n\n"; } cout << "Another equation to solve? Type Y for YES, N for NO: ";
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Homework4 - HW #4 1. #include &lt;iostream&gt; #include...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online