C++ Program to Find All The Roots Of A Quadratic Equation andrey вторник, 30 сентября 2014 г. No Comment


A quadratic equation has the form ax^2+bx+c=0 where x is an unknown, and a, b, c represent values which in this c++ program will be supplied by the user.



Also Read: C++ Program To compute least common multiple

#include
#include
#include


void main()
{
float a,b,c,d,x1,x2;

cout<<"Enter the value of a: ";
cin>>a;
cout<<"Enter the value of b: ";
cin>>b;
cout<<"Enter value of c: ";
cin>>c;

d=b*b-4*a*c;

if(d==0)
{
x1=(-b)/(2*a);
x2=root1;
cout<<"The Roots are real & equal";
}
else if(d>0)
{
x1=-(b+sqrt(d))/(2*a);
x2=-(b-sqrt(d))/(2*a);
cout<<"the Roots are real & distinct";
}
else
{
x1=(-b)/(2*a);
x2=sqrt(-d)/(2*a);
cout<<"Roots are imaginary";
}

cout<" "<}

A quadratic equation has the form ax^2+bx+c=0 where x is an unknown, and a, b, c represent values which in this c++ program will be supplied by the user.



Also Read: C++ Program To compute least common multiple

#include
#include
#include


void main()
{
float a,b,c,d,x1,x2;

cout<<"Enter the value of a: ";
cin>>a;
cout<<"Enter the value of b: ";
cin>>b;
cout<<"Enter value of c: ";
cin>>c;

d=b*b-4*a*c;

if(d==0)
{
x1=(-b)/(2*a);
x2=root1;
cout<<"The Roots are real & equal";
}
else if(d>0)
{
x1=-(b+sqrt(d))/(2*a);
x2=-(b-sqrt(d))/(2*a);
cout<<"the Roots are real & distinct";
}
else
{
x1=(-b)/(2*a);
x2=sqrt(-d)/(2*a);
cout<<"Roots are imaginary";
}

cout<" "<}
by Jillur Rahman

Jillur Rahman is a Web designers. He enjoys to make blogger templates. He always try to make modern and 3D looking Templates. You can by his templates from Themeforest.

Follow him @ Twitter | Facebook | Google Plus

No Comment