Description:
This program take three constants of quadratic equation as input and find real and imaginary roots of that quadratic equation automatically.
Code:
This program take three constants of quadratic equation as input and find real and imaginary roots of that quadratic equation automatically.
Code:
#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
float a,b,c,d,f,e,g,h,i,j,k,l;
cout<<"A programe to find the roots of quadratic equation"<<endl;
xy:
cout<<"Enter the values of a,b,c"<<endl;
cout<<"Enter value of a"<<endl;
cin>>a;
cout<<endl<<"Enter the value of b"<<endl;
cin>>b;
cout<<endl<<"Enter the value of c"<<endl;
cin>>c;
cout<<endl;
d=b*b-(4*a*c);
if(d>0||d==0)
{
f=(-b+sqrt(d))/(2*a);
e=(-b-sqrt(d))/(2*a);
cout<<"The required roots are"<<endl<<"The first root is ="<<f<<endl<<"The second root is ="<<e<<endl;
}
if(d<0)
{
g=-b/(2*a);//x1
h= sqrt(-d)/(2*a);//x1
j=-sqrt(-d)/(2*a);//x2
k=g+h;
l=g+j;
cout<<"the required roots are"<<endl;
cout<<"first root="<<k<<"i"<<endl;
cout<<"second root="<<l<<"i"<<endl;
}
goto xy;
getche();
return 0;
}
No comments:
Post a Comment