*** 第 5 點 (20%):WA (line:1)
您的答案為: Two same roots x=-4
正確答案為: Two same roots x=-1
以下是我的程式碼:
#include <iostream>
using namespace std;
#include <math.h>
int main()
{
double a,b,c,x1,x2;
while(cin>>a>>b>>c)
{
x1 = (-b+sqrt(b*b-4*a*c))/2*a;
x2 = (-b-sqrt(b*b-4*a*c))/2*a;
if((b*b-4*a*c) > 0)
{
if((x1-x2) > 0)
cout<<"Two different roots x1="<<x1<<" , "<<"x2="<<x2<<endl;
else
cout<<"Two different roots x1="<<x2<<" , "<<"x2="<<x1<<endl;
}
else
if((b*b-4*a*c) == 0)
{
if(x1 == x2)
cout<<"Two same roots x="<<x1<<endl;
}
else
if((b*b-4*a*c) < 0)
cout<<"No real root"<<endl;
}
return 0;
}
我2根那邊不知道出了什麼問題.....