steemibu351 avatar

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

steemibu351

Published: 14 Dec 2021 › Updated: 14 Dec 2021A simple c++ code to solve a quadratic equation.

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

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();

}

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

Written by

Read more #programming posts


Best Posts From steemibu351

We have not curated any of steemibu351's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From steemibu351