/* PROGRAM TO COMPUTE THE ROOTS OF THE QUADRATIC EQUATION */
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
float a,b,c;
clrscr();
cout<<"Enter Coefficients of the equation"<<endl;
cin>>a>>b>>c;
if(a==0)
{
cout<<"\n This is not a quadratic equation ";
return 0;
}
cout<<"\n The equation is ::"<<a<<"x^2+"<<b<<"x+"<<c<<"=0\n";
double d,x1,x2,d2;
d=(b*b)-(4*a*c);
if(d<0)
{
//cout<<"\n This equation has no real solution"<<endl;
d=((-1)*(d));
d2=sqrt(d);
x1=(-b)/(2*a);
x2=(d2)/(2*a);
cout<<"\n The roots are :: "<<x1<<"+"<<x2<<"i"<<" & "
<<x1<<"-"<<x2<<"i"<<endl;
cout<<"\n Where 'i' is Euler's Number"<<endl;
getch();
return 0;
}
d2=sqrt(d);
x1=(-b+d2)/(2*a);
x2=(-b-d2)/(2*a);
cout<<"\n The roots are :: "<<x1<<" & "<<x2<<endl;
getch();
return 0;
}
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
float a,b,c;
clrscr();
cout<<"Enter Coefficients of the equation"<<endl;
cin>>a>>b>>c;
if(a==0)
{
cout<<"\n This is not a quadratic equation ";
return 0;
}
cout<<"\n The equation is ::"<<a<<"x^2+"<<b<<"x+"<<c<<"=0\n";
double d,x1,x2,d2;
d=(b*b)-(4*a*c);
if(d<0)
{
//cout<<"\n This equation has no real solution"<<endl;
d=((-1)*(d));
d2=sqrt(d);
x1=(-b)/(2*a);
x2=(d2)/(2*a);
cout<<"\n The roots are :: "<<x1<<"+"<<x2<<"i"<<" & "
<<x1<<"-"<<x2<<"i"<<endl;
cout<<"\n Where 'i' is Euler's Number"<<endl;
getch();
return 0;
}
d2=sqrt(d);
x1=(-b+d2)/(2*a);
x2=(-b-d2)/(2*a);
cout<<"\n The roots are :: "<<x1<<" & "<<x2<<endl;
getch();
return 0;
}
No comments:
Post a Comment