|
Master Member
您的住址: 楓葉與霜晶的華爾滋
文章: 1,862
|
請問各位這題c語言的while迴圈的答案為何是無限
#include <stdio.h>
#include <stdlib.h>
int main(void){
int counter=0;
float total=0.00;
while(total!=1.00){
total=total+0.01;
counter=counter+1;
printf("每次的total=%f\n",total);
printf("每次的counter=%d\n",counter);
}
printf("答案是:%d",counter);
system("PAUSE");
return 0;
}
------------------------
compile之後執行的結果也的確是如此,因為到了某一數值(0.830000)時後面的數字開始亂跳,使得迴圈永遠成立,只是為何條件設定是0.01累加,為何尾數應該是0的部分會成亂數跳躍呢?謝謝各位
__________________
|