Friday, February 13, 2015
C Program to calculate roots of quadratic equation ax 2 bx c 0
#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<<"Quadratic Equation is ax^2=bx+c=0";
cout<<" Enter values of a,b and c:";
cin>>a>>b>>c;
d=(b*b)-(4*a*c);
if(d>0)
{
cout<<"
Two real and distinct roots";
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
cout<<"
Roots are "<<root1<<" and "<<root2;
}
else
if(d==0)
{
cout<<"
Two real and equal roots";
root1=root2=-b/(2*a);
cout<<"
Roots are "<<root1<<" and "<<root2;
}
else
cout<<"
Roots are COMPLEX and IMAGINARY....!!!";
getch(); //to stop the screen
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.