Program for Finding Roots of Quadratic Equation
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,d,r1,r2;
clrscr();
cout<<"Program by: \n\t HAKIM VOHRA"<<endl;
cout<<"Finding Roots of Quadratic Equation"<<endl;
cout<<"Enter a: ";
cin>>a;
cout<<"Enter b: ";
cin>>b;
cout<<"Enter c: ";
cin>>c;
cout<<"\t"<<a<<"x^2+"<<b<<"x+"<<c<<"=0"<<endl;
d=(b*b)-4*a*c;
if(d<0)
{
cout<<"IMAGINARY ROOTS";
}
else if(d<0)
{
r1=-b+sqrt(d)/2*a;
r2=-b-sqrt(d)/2*a;
cout<<"ROOTS ARE: "<<r1<<" "<<r2<<endl;
}
else
{
r1=-b/2*a;
r2=-b/2*a;
cout<<"ROOTS ARE EQUAL: "<<r1<<" "<<r2<<endl;
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,d,r1,r2;
clrscr();
cout<<"Program by: \n\t HAKIM VOHRA"<<endl;
cout<<"Finding Roots of Quadratic Equation"<<endl;
cout<<"Enter a: ";
cin>>a;
cout<<"Enter b: ";
cin>>b;
cout<<"Enter c: ";
cin>>c;
cout<<"\t"<<a<<"x^2+"<<b<<"x+"<<c<<"=0"<<endl;
d=(b*b)-4*a*c;
if(d<0)
{
cout<<"IMAGINARY ROOTS";
}
else if(d<0)
{
r1=-b+sqrt(d)/2*a;
r2=-b-sqrt(d)/2*a;
cout<<"ROOTS ARE: "<<r1<<" "<<r2<<endl;
}
else
{
r1=-b/2*a;
r2=-b/2*a;
cout<<"ROOTS ARE EQUAL: "<<r1<<" "<<r2<<endl;
}
getch();
}
No comments:
Post a Comment