#12197: c-----輸出短少


jjooee1998 (yes,it unknown)


常常遇到輸出短少的情況,是哪個地方出了問題呢??

請高手指教,謝謝!!

 

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int a,b,c,d;
int a1,a2;
while(scanf ("%d%d%d",&a,&b,&c)!=EOF)
{
d=b*b-4*a*c;
if(d>0){
a1=(-b+sqrt(b*b-4*a*c))/(2*a);
a2=(-b-sqrt(b*b-4*a*c))/(2*a);
printf("Two different roots x1=%d , x2=%d",a1,a2);
}
else
if(d=0){
a2=-sqrt(c);
printf("Two same roots x=%d",a2);
}
else
if(d<0){
printf("No real root");
}
}
return 0;
}

 

#12198: Re:c-----輸出短少


anandrewboy70900 (ShowTsai)


 

else裡面

if(d == 0)




#12202: Re:c-----輸出短少


jjooee1998 (yes,it unknown)


 

else裡面

if(d == 0)





感謝您,我已作修正,並加了break,若不加break輸出的值將一直重複,但我加了break變輸出短少,請問該用哪個做修正呢?

#12204: Re:c-----輸出短少


anandrewboy70900 (ShowTsai)


 

不用break
你輸出沒有換行

printf("Two different roots x1=%d , x2=%d\n",a1,a2);

printf("Two same roots x=%d\n",a2);

printf("No real root\n");

然後重根那裏

應該是a2 = -b/(2*a)




#12205: Re:c-----輸出短少


anandrewboy70900 (ShowTsai)


 
喔 你已經過了
沒看到







#12207: Re:c-----輸出短少


jjooee1998 (yes,it unknown)


 
喔 你已經過了
沒看到







非常謝謝您願意花時間幫我做修正!!