[ZJ]a006. 一元二次方程式
題目:
http://zerojudge.tw/ShowProblem?problemid=a006
--------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a, b, c;
while (cin >>a >>b >>c ){
if (b*b -4*a*c <0)
cout << "No real root";
else if (b*b -4*a*c ==0)
cout <<"Two same roots x=" <<-b /(2*a) ;
else
cout << "Two different roots x1=" << (-b + sqrt(b*b-4*a*c)) / (2*a)
<< " , x2=" << (-b - sqrt(b*b-4*a*c)) / (2*a) ;
cout <<endl ;
}
return 0;
}
http://zerojudge.tw/ShowProblem?problemid=a006
--------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a, b, c;
while (cin >>a >>b >>c ){
if (b*b -4*a*c <0)
cout << "No real root";
else if (b*b -4*a*c ==0)
cout <<"Two same roots x=" <<-b /(2*a) ;
else
cout << "Two different roots x1=" << (-b + sqrt(b*b-4*a*c)) / (2*a)
<< " , x2=" << (-b - sqrt(b*b-4*a*c)) / (2*a) ;
cout <<endl ;
}
return 0;
}
留言
張貼留言