到底錯在哪裡> <"
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int a,b,c,d,e,f;
while (cin>>a>>b>>c)
{
d = sqrt(b*b-a*4*c);
e = (-b+d)/2*a;
f = (-b-d)/2*a;
if(b*b-4*a*c > 0)
{
if(e>f)
cout<<"Two different roots x1="<<e<<" , x2="<<f<<endl;
else if(f>e)
cout<<"Two different roots x1="<<f<<" , x2="<<e<<endl;
}
else if(b*b-4*a*c == 0)
{
cout<<"Two same roots x="<<e<< endl;
}
else if (b*b-4*a*c < 0)
{
cout<<"No real root"<<endl;
}
}
return 0;
}
*** 第 5 點 (20%):WA (line:1)
您的答案為: Two same roots x=-4
正確答案為: Two same roots x=-1
到底錯在哪裡> <"
#include
#include
using namespace std;
int main()
{
int a,b,c,d,e,f;
while (cin>>a>>b>>c)
{
d = sqrt(b*b-a*4*c);
e = (-b+d)/2*a;
f = (-b-d)/2*a;
if(b*b-4*a*c > 0)
{
if(e>f)
cout<<"Two different roots x1="< }
}
return 0;
}
*** 第 5 點 (20%):WA (line:1)
您的答案為: Two same roots x=-4
正確答案為: Two same roots x=-1