int main(void)
{
float num,sum=0,avg;
int count=0;
while(1)
{
scanf("%f",&num);
if(num==Y)break;
count++;
sum=sum+num;
}
if(count!=0)
avg=sum/count;
printf("平均值為:%f",avg);
return 0;
}
為什麼當輸入num==Y時就不能算出平均值。謝謝
int main(void)
{
float num,sum=0,avg;
int count=0;
while(1)
{
scanf("%f",&num);
if(num==0)break;
count++;
sum=sum+num;
}
if(count!=0)
avg=sum/count;
printf("平均值為:%f",avg);
return 0;
}
注:輸入0時,退出!!