Thursday, 19 July 2018

Roots of Quadratic Equation

===========================================================================
                                CODING



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

void main()
{
clrscr();

double a,b,c,D,x1,x2,x3;
cout<<"\n Enter coffecient of x²: ";
cin>>a;
cout<<"\n Enter coffecient of x : ";
cin>>b;
cout<<"\n Enter coffecient of constant: ";
cin>>c;
D=pow(b,2)-4*a*c;
if(D<0)
{cout<<"\n The eq. has unreal roots, sorry!";}
else if(D==0)
{x3=-1*b/(2*a);
cout<<"\n The roots of the eq. are same and equal to: "<<x3;}
else
{x1=(-1*b+sqrt(D))/(2*a);
x2=(-1*b-1*sqrt(D))/(2*a);
cout<<"\n The roots of eq. are real and unqual: "<<x1<<" and "<<x2;}
getch();
}

===========================================================================


                                OUTPUT



No comments:

Post a Comment