Homework4

# Homework4 - HW#4 1#include #include using...

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

HW #4

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

View Full Document
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";
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: ";

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/07/2011 for the course EEL 0565 taught by Professor Khabou during the Spring '11 term at W. Florida.

### Page1 / 5

Homework4 - HW#4 1#include #include using...

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

View Full Document
Ask a homework question - tutors are online