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";
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment