#include<iostream>
#include<math.h>
using namespace std;
main() {
float a,b,c; double d; //because sqrt function accepts double data type
cout<<"Enter the Coefficient 'a' : "; cin>>a;
while(a == 0) //if a=0, take the input again
{ cout<<"Enter a Non-Zero value for 'a' : "; cin>>a;
}
cout<<"Enter the coefficient 'b' : "; cin>>b;
cout<<"Enter the coefficient 'c' : "; cin>>c;
d = b*b - 4*a*c; //computing the determinant
if(d == 0)
{
cout<<"\nRoots are Real and Equal"<<endl<<endl;
cout<<"Root 1 is "<<-b/(2*a)<<endl;
cout<<"Root 2 is "<<-b/(2*a)<<endl; }
else if(d > 0) {
cout<<"\nRoots are Real and Different"<<endl<<endl;
cout<<"Root 1 is "<< (-b + sqrt(d))/2*a<<endl;
cout<<"Root 2 is "<< (-b - sqrt(d))/2*a<<endl; }
else {
d = (-1*d); //making determinant positive, because you cannot directly compute the square root of a negative number in c++
cout<<"\nRoots are Complex and Different"<<endl<<endl;
cout<<"Root 1 is "<<-b/(2*a)<<" + i "<<sqrt(d)/2*a<<endl;
cout<<"Root 2 is "<<-b/(2*a)<<" - i "<<sqrt(d)/2*a<<endl; }
system("pause"); }}