# 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.

Expert's answer

#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;};

}

#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 orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment