#include<iostream.h>
#include<conio.h>
#include<math.h> //to claculate square root
void main()
{
clrscr(); //to clear the screen
float root1,root2,a,b,c,d;
cout<<"\n Quadratic Equation is ax^2=bx+c=0";
cout<<"\n Enter values of a,b and c : ";
cin>>a>>b>>c;
d=(b*b)-(4*a*c);
if(d>0)
{
cout<<"\n Two real and distinct roots";
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
cout<<"\n Roots are "<<root1<<" and "<<root2;
}
else
if(d==0)
{
cout<<"\n Two real and equal roots";
root1=root2=-b/(2*a);
cout<<"\n Roots are "<<root1<<" and "<<root2;
}
else
cout<<"\n Roots are COMPLEX and IMAGINARY....!!!";
getch(); //to stop the screen
}
Output

#include<conio.h>
#include<math.h> //to claculate square root
void main()
{
clrscr(); //to clear the screen
float root1,root2,a,b,c,d;
cout<<"\n Quadratic Equation is ax^2=bx+c=0";
cout<<"\n Enter values of a,b and c : ";
cin>>a>>b>>c;
d=(b*b)-(4*a*c);
if(d>0)
{
cout<<"\n Two real and distinct roots";
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
cout<<"\n Roots are "<<root1<<" and "<<root2;
}
else
if(d==0)
{
cout<<"\n Two real and equal roots";
root1=root2=-b/(2*a);
cout<<"\n Roots are "<<root1<<" and "<<root2;
}
else
cout<<"\n Roots are COMPLEX and IMAGINARY....!!!";
getch(); //to stop the screen
}
Output
No comments:
Post a Comment