#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;
int main(){
float 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(d<0)
cout <<"No real root" <<endl;
else if(d>0){
if(e>f)
cout << "Two different roots x1=" << e << " , x2=" << f << endl;
else if(e<f)
cout << "Two different roots x1=" << f << " , x2=" << e << endl;
}
else if(d==0){
if(b==0)cout << "Two same roots x=" << b/2*a << endl;
else cout << "Two same roots x=" << -b/2*a << endl;}
}
return 0;
}
他的No real root一直跑不出來,而且最後一項一直跑出
*** 第 5 點 (20%):WA
與正確輸出不相符(line:1)
您的答案為: Two same roots x=-4
正確答案為: Two same roots x=-1
請問能告訴我為什麼嗎?
謝謝 > <
#include
#include
#include
#include
using namespace std;
int main(){
float 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(d<0)
cout <<"No real root" < else if(d>0){
if(e>f)
cout << "Two different roots x1=" << e << " , x2=" << f << endl;
else if(e cout << "Two different roots x1=" << f << " , x2=" << e << endl;
}
else if(d==0){
if(b==0)cout << "Two same roots x=" << b/2*a << endl;
else cout << "Two same roots x=" << -b/2*a << endl;}
}
return 0;
}
他的No real root一直跑不出來,而且最後一項一直跑出
*** 第 5 點 (20%):WA
與正確輸出不相符(line:1)
您的答案為: Two same roots x=-4
正確答案為: Two same roots x=-1
請問能告訴我為什麼嗎?
謝謝 > <