A simple c++ code to solve a quadratic equation.

in programming •  3 years ago 

Screenshot_24.png

After include in first line there must be written "iostream" inside <>.

#include
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
int si;
float a,b,c,d,root1,root2,real,imaginary;
while(true)
{
cout<<"enter the serial number"<<endl;
cin>>si;
if(si==0)
{
break;
}
cout<<"enter the value of a"<<endl;
cin>>a;
cout<<"enter the value of b"<<endl;
cin>>b;
cout<<"enter the value of c"<<endl;
cin>>c;
d=bb-4ac;
if(d>0)
{
root1=(-b+sqrt(d))/(2
a);
root2=(-b-sqrt(d))/(2a);
cout<<"the roots are real and different"<<endl;
cout<<"root1="<<root1<<endl;
cout<<"root2="<<root2<<endl;
}
else if(d<0)
{
real=-b/(2
a);
imaginary=(sqrt(-d))/(2a);
cout<<"the roots are complex and different"<<endl;
cout<<"root1="<<real<<"+i"<<imaginary<<endl;
cout<<"root2="<<real<<"-i"<<imaginary<<endl;
}
else
{
root1=-b/(2
a);
root2=root1;
cout<<"the roots are real and equal"<<endl;
cout<<"root1=root2="<<root1<<endl;
}

}
getch();

}

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE BLURT!