Answer to Question #857 in C++ for Alemseged

Question #857
Describe an algorithm that computes the roots of a quadratic equation and display the roots.
1
Expert's answer
2010-10-28T12:38:54-0400
#include <iostream.h>
#include <math.h>
// ax^2+bx+c=0;
main()
{
double a, b, c;
double D;// descriminant
double x1,x2;// solution
cout<<"Write a, b, c"
cin>>a; cin>>b; cin>>c;
D=b*b-4*a*c;
if (D<0) cout<<"No roots in real nembers";
if(D>0) {x1=(-1*b+Sqrt(D))/(2*a); x2=(-1*b-Sqrt(D))/(2*a);
cout<<x1;
cout<<" ";
cout<<x2;
}
if (D==0) {x1=-1*b/(2*a); cout<<x1;};

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS