int main() {
int a, b, c, d, e, f;
while(scanf("%d%d%d", &a, &b, &c)!=EOF){
d = b * b - 4 * a * c;
if(d > 0){
e = (-b+sqrt(b*b-4*a*c))/(2*a);
f = (-b-sqrt(b*b-4*a*c))/(2*a);
printf("Two different roots x1=%d , x2=%d\n", e, f);
}else if (d == 0){
f = -sqrt(c);
printf("Two same roots x=%d\n", f);
}else {
printf("No real root\n");
}
}
return 0;
}
您的答案為: Two same roots x=-1 正確答案為: Two same roots x=1
請問哪裡錯誤呢?
int main() {
int a, b, c, d, e, f;
while(scanf("%d%d%d", &a, &b, &c)!=EOF){
d = b * b - 4 * a * c;
if(d > 0){
e = (-b+sqrt(b*b-4*a*c))/(2*a);
f = (-b-sqrt(b*b-4*a*c))/(2*a);
printf("Two different roots x1=%d , x2=%d\n", e, f);
}else if (d == 0){
f = -sqrt(c);
printf("Two same roots x=%d\n", f);
}else {
printf("No real root\n");
}
}
return 0;
}
您的答案為: Two same roots x=-1 正確答案為: Two same roots x=1
請問哪裡錯誤呢?
重跟 不是-sqrt(c)
試試 1 -2 1