PROGRAM ON FINDING THE ROOTS OF QUADRATIC EQUATION
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,root1,root2,delta;
clrscr();
cout<<"Enter the three no. a,b and c of"<<" ax^2+bx+c:\n";
cin>>a>>b>>c;
if(!a)
cout<<"Value of\'a\'should not be zero:"<<"\n Aborting!!!!"<<"\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<<" Root2="<<root2<<"\n";
}
else if(delta==0)
{
root1=-b/(2*a);
cout<<"Roots are REAL and EQUAL"<<"\n";
cout<<"Root1="<<root1<<" Root2="<<root2<<"\n";
}
else
cout<<"Roots are COMPLEX and IMAGINARY"<<"\n";
}
getch();
}
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,root1,root2,delta;
clrscr();
cout<<"Enter the three no. a,b and c of"<<" ax^2+bx+c:\n";
cin>>a>>b>>c;
if(!a)
cout<<"Value of\'a\'should not be zero:"<<"\n Aborting!!!!"<<"\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<<" Root2="<<root2<<"\n";
}
else if(delta==0)
{
root1=-b/(2*a);
cout<<"Roots are REAL and EQUAL"<<"\n";
cout<<"Root1="<<root1<<" Root2="<<root2<<"\n";
}
else
cout<<"Roots are COMPLEX and IMAGINARY"<<"\n";
}
getch();
}
Comments
Post a Comment