Friday, 3 February 2012
C++ - quadratic equation solver
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int a , b , c ;
float x1,x2,x;
cout << "\nPlease enter the coefficients, separated by spaces : ";
cin >> a >> b >> c;
cout << "\nYou enter a = " << a << ", b = " << b << " c = " << c << "." << endl;
x=(b*b)-(4*a*c);
if (a==0)
cout << "\nERROR : Unable to compute the equation!!!" << endl;
else
{
x1=(-b+sqrt(x))/(2*a);
x2=(-b-sqrt(x))/(2*a);
cout << "\nThe equation is : " << a << "x^2+" << b << "x" << c << endl;
cout<< "\nThe solution are : " << x1 <<" and " << x2 << endl;
}
system ("pause");
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment