Make Your Search Easy ! :) Use me

Wednesday, February 22, 2017

Roots of Quadratic Equation

Program to find root of Quadratic Equation :-


#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>

void main()
{
float a,b,c,D,r1,r2;
cout<<"\t\tWelcome to Root Finder\n\n";
cout<<"Enter 'a', 'b' and 'c' of quadratic equation "<<endl;
cin>>a>>b>>c;
D=(pow(b,2))-4*a*c;
if(D==0)
{
cout<<"\nThe equation has identical roots.";
}
else if(D>0)
{
cout<<"\nThe equation has 2 real different roots.";
}
else
{
cout<<"\nThe equation has no real roots.";
exit(0);
}
r1=(-b+sqrt(D))/2*a;
r2=(b+sqrt(D))/2*a;
cout<<"\nThe roots of the equation are "<<r1<<" and "<<r2;
getch();
}

No comments:

Post a Comment