PROGRAM
//Program to calculate and print the roots of a quadratic equation!
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float a,b,c, delta,root1,root2;
cout<<"ENTER three numbers a, b and c of ax^2+bx+c:\n";
cin>>a>>b>>c;
if(!a)
cout<<"VALUE CANNOT BE ZERO"<<"\nABORTING!!!...\n";
else
{
delta= (b*b) - (4 * a * c);
if(delta>0)
{
root1= (-b + sqrt(delta))/(2*a);
root2= (-b - sqrt(delta))/(2*a);
cout<<"ROOTS ARE REAL AND UNEQUAL:\n";
cout<<"Root1="<<root1;
cout<<"\nRoot2="<<root2;
}
else if(delta==0)
{
root1= -b/(2*a);
cout<<"ROOTS ARE REAL AND EQUAL:\n";
cout<<"Root1="<<root1;
cout<<"Root2="<<root1;
}
else
{
cout<<"ROOTS ARE COMPLEX AND IMAGINARY \n";
}
}
return 0;
}
OUTPUT
//Program to calculate and print the roots of a quadratic equation!
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float a,b,c, delta,root1,root2;
cout<<"ENTER three numbers a, b and c of ax^2+bx+c:\n";
cin>>a>>b>>c;
if(!a)
cout<<"VALUE CANNOT BE ZERO"<<"\nABORTING!!!...\n";
else
{
delta= (b*b) - (4 * a * c);
if(delta>0)
{
root1= (-b + sqrt(delta))/(2*a);
root2= (-b - sqrt(delta))/(2*a);
cout<<"ROOTS ARE REAL AND UNEQUAL:\n";
cout<<"Root1="<<root1;
cout<<"\nRoot2="<<root2;
}
else if(delta==0)
{
root1= -b/(2*a);
cout<<"ROOTS ARE REAL AND EQUAL:\n";
cout<<"Root1="<<root1;
cout<<"Root2="<<root1;
}
else
{
cout<<"ROOTS ARE COMPLEX AND IMAGINARY \n";
}
}
return 0;
}
OUTPUT