5 December 2011

To Find Discriminant & Square Roots Of The Equation A simple C++ program.

#include // Header File
#include
int main()
{
long double a,b,c; //
Declaration of value
cout<<"Enter the value of
a :";
cin>>a;
cout<<"Enter the value of
b :"; // Input to be give by
the user
cin>>b;
cout<<"Enter the value of
c :";
cin>>c;
double d=(pow(b,2)-4*a*c);
// mathematical fuction
if (d==0)
{
cout<<"The discriminant
is : ";
cout<cout<<"The equation
has single roots";
p=(((-b)+sqrt(d))/(2*a));
n=(((-b)-sqrt(d))/(2*a));
cout<<"The roots of the
equation x= ";
}
else if (d>0)
{
cout<<"The discriminant
is : ";
cout<cout<<"The equation
has two roots";
p=(((-b)+sqrt(d))/(2*a));
n=(((-b)-sqrt(d))/(2*a));
cout<<"The roots of the
equation x= ";
}
else
{
cout<<"The discriminant
is : ";
cout<cout<<"The equation
has complex roots";
}
cout<< p; // output to be
generated
cout<<";";
cout<< n<< endl<
return 0;
}

0 comments:

Post a Comment