Answer to Question #16428 in C++ for Phillip

Question #16428
The roots of the quadratic equation ax2+bx+c=0. In this formula, the term is called discriminant. If , then the equation has a single (repeated) root. If the equation has two real roots. If , the equation has two complex roots ie no real roots. Using the concept of passing values to a function write a C++ program that computes real roots of a quadratic equation.
1
Expert's answer
2012-10-30T11:12:42-0400
#include<iostream>
#include<cmath>
using namespace std;

double a, b, c, D, x1, x2;

void main(){

cout<<"enter the coefficient a: ";
cin>>a;
cout<<"enter the coefficient b: ";
cin>>b;
cout<<"enter the coefficient c: ";
cin>>c;

D = b*b-4*a*c;
if (D==0) cout<<"the single root is "<<-b+sqrt(D)/(2*a)<<"\n";
if (D<0)& cout<<"there are no roots.\n";
if (D>0)& cout<<"The roots are:\n"<<-b+sqrt(D)/(2*a)<<"\n"<<-b-sqrt(D)/(2*a)<<"\n";

system("pause");

}



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