Friday, September 9, 2016

PROGRAM TO FIND ROOTS OF A QUADRATIC EQUATION:

Tags

PROGRAM TO FIND ROOTS OF A QUADRATIC EQUATION:

#include<iostream>
using namespace std;
#include<cmath>
class roots
{
 float  a,b,c,d,x,y;
float r,i;
public:
void disc()
{cout<<"ENTER THE COFFICIENTS AND CONSTANT OF QUADRATIC EQUATION ";
cin>>a>>b>>c;
d=b*b-4*a*c;
cout<<"ROOTS OF EQUATION ARE\n";
if(d==0)
{x=y=(-b+sqrt(d))/2*a;
   cout<<x<<"\n"<<y; }
else if(d>0)
{x=(-b+sqrt(d))/2*a;
y=(-b-sqrt(d))/2*a;
cout<<x<<"\n"<<y;
}
else
{r=-b/2*a;
d=-d;
i=sqrt(d)/2*a;
cout<<r<<"+"<<"i"<<i<<"\n";
cout<<r<<"-"<<"i"<<i;
}
}

};
int main()
{roots r;
r.disc();
}
also read program to print triangle of stars CLICK HERE