#include <iostream.h>
#include <math.h>
void main()
{
float a , b , c , d , e ;
float temp , r1 , r2 ;
int select ;
char ans ;
do
{
cout<<"Enter the coefficients of the Quadratic equation :\n";
cin>>a>>b>>c;
temp = (b * b) - (4 * a * c) ;
if (temp > 0)
select = 0 ;
else
if (temp == 0)
select = 1 ;
else
select = 2 ;
switch (select)
{
case 0 :
temp = sqrt (temp) ;
r1 = (-b + temp) / (2 * a) ;
r2 = (-b - temp) / (2 * a) ;
cout<<"The roots are Real and Unequal.\n";
cout<<"The roots are : "<<r1<<" "<<r2;
break ;
case 1 :
r1 = -b / (2 * a) ;
r2 = r1 ;
cout<<"The roots are Real and Equal.\n";
cout<<"The roots are : "<<r1<<" "<<r2;
break ;
case 2 :
temp = -temp ;
temp = sqrt (temp) ;
temp = temp / (2 * a) ;
r1 = -b / (2 * a) ;
cout<<"The roots are Real and Imaginary.\n";
cout<<"The roots are : "<<r1<<"+j"<<temp<<" , "<<r1<<"-j"<<temp;
break ;
}
cout<<"Do you want to continue (Y or N) ? :\n";
cin>>ans;
}
while ((ans == 'y') || (ans == 'Y')) ;
}
0 comments:
Post a Comment