77 426
Assignments Done
Successfully Done
In July 2019

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.
Expert's answer
using namespace std;

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

void main(){

cout<<"enter the coefficient a: ";
cout<<"enter the coefficient b: ";
cout<<"enter the coefficient 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";



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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions