C++ program to find whether the equation is real or imaginary and also finds roots of that Equation

The roots of the equation ax^2 +bx+c=0 are a and b. And to find whether it is imaginary or not we use the formulae d=b^2-4ac , if d < 0  then the solution of the equation is imaginary and if greater than zero then its solution is real.

#include<iostream>
using namespace std;
int main()
{


int a,b,c,d,x,y;
cout <<"Enter the values of a,b and c in Ax^2+Bx+C\n";
cin >> a;
cin >> b;
cin >> c;
d=b*b-(4*a*c);
if(d<0)
{
cout << " Its solution is imaginary\n";
}
else
{
cout << " Its solution is real \n";
x=(-b+d)/(2*a);
y=(-b-d)/(2*a);
cout << "Roots : " << x;
cout << ", "<< y; 
}
return 0;
}

Post a Comment

0 Comments