Pages

Monday, July 25, 2011

a006. 一元二次方程式


#include
#include
using namespace std;

int main()
{
int a, b, c;
while( cin >> a >> b >> c )
{
int sqrtOfThis=sqrt((double)(b*b-4*a*c));
if( b*b - 4*a*c < 0 )
cout << "No real root\n";
else if( b*b - 4*a*c == 0 )
cout << "Two same roots x=" << -b/(2*a) << endl;
else
cout << "Two different roots x1=" << (-b + sqrtOfThis ) / (2*a)
<< " , x2=" << (-b - sqrtOfThis) / (2*a) << endl;
}
return 0;
}

No comments:

Post a Comment