What should be the output format for imaginary roots , it is not specified ???
I have printed in form of ‘i’ but one testcase is incorrect.
Here is my code…
#include
#include<math.h>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
float x1,x2;
float d;
d= (bb)-(4a*c);
x1 = (-b + sqrt(d))/(2*a);
x2 = (-b - sqrt(d))/(2*a);
if(d>0)
{
cout<<"Real and Distinct"<<endl;
cout<<x2<<" "<<x1;
}
else if(d==0)
{
cout<<"Real and Equal"<<endl;
cout<<x2<<" "<<x1;
}
else
{
cout<<"Imaginary"<<endl;
float realpart = (-b)/(2*a);
float imaginarypart = sqrt(-d)/(2*a);
cout<<realpart<<"+i"<<imaginarypart<<" ";
cout<<realpart<<"-i"<<imaginarypart<<endl;
}
return 0;
}