求各位高手看一下小弟的程式
#include <stdio.h>
#include <math.h>
int main(void) {
int a,b,c,x,y,temp;
while(scanf("%d%d%d",&a,&b,&c)!= EOF){
x = (-b+pow(pow(b,2)-4*a*c,0.5))/2*a;
y = (-b-pow(pow(b,2)-4*a*c,0.5))/2*a;
if (x <= -100000 && y <= -100000){
printf("No real root\n");
}
else{
if (x == y ){
printf("Two same roots x=%d\n",x);
}
else{
if(x <= y) {
printf("Two different roots x1=%d , x2=%d\n",y,x);
}
else{
printf("Two different roots x1=%d , x2=%d\n",x,y);
}
}
}
}
return 0;
}
正確答案是 X = -1 我的是 X = -4
求解TAT謝謝
求各位高手看一下小弟的程式
#include
#include
int main(void) {
int a,b,c,x,y,temp;
while(scanf("%d%d%d",&a,&b,&c)!= EOF){
x = (-b+pow(pow(b,2)-4*a*c,0.5))/2*a;
y = (-b-pow(pow(b,2)-4*a*c,0.5))/2*a;
if (x <= -100000 && y <= -100000){
printf("No real root\n");
}
else{
if (x == y ){
printf("Two same roots x=%d\n",x);
}
else{
if(x <= y) {
printf("Two different roots x1=%d , x2=%d\n",y,x);
}
else{
printf("Two different roots x1=%d , x2=%d\n",x,y);
}
}
}
}
return 0;
}
正確答案是 X = -1 我的是 X = -4
求解TAT謝謝
再 /2*a 這裡要加上掛號 /(2*a) 不然會變成除以二再乘a