Print Friendly and PDF
For ax2 + bx + c = 0, the value of x is given by: For the Quadratic Formula to work, you must have yourequation arranged in the form "(quadratic) = 0". Also, the "2a" in the denominator of the Formula is underneath everything above, not just the square roots



 Roots of a Quadratic Equation


#include <iostream.h> 
#include <conio.h> 
#include <math.h> 
using namespace std;
int main() 
{ 

float a,b,c,d,root1,root2; 
cout << "Enter the 3 coefficients a, b, c : " << endl; 
cin>>a>>b>>c; 
if(!a) 
{ 
if(!b) 
cout << "Both a and b cannot be 0 in ax^2 + bx + c = 0" << "\n"; 
else 
{ 
d=-c/b; 
cout << "The solution of the linear equation is : " << d << endl; 
} 
} 
else 
{ 
d=b*b-4*a*c; 
if(d>0) 
root1=(-b+sqrt(d))/(2*a); 
root2=(-b-sqrt(d))/(2*a); 
cout << "The first root = " << root1 << endl; 
cout << "The second root = " << root2 << endl; 
} 
return 0; 
}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: