大家好,新手问下这程序错误在哪···
跟隔壁帖子一样是求1-100间奇数的平均值# include<stdio.h>
int main(void)
{
int i;
int sum = 0;
int cnt = 0;
float avg;
for (i = 1;i < 101; ++i)
{
if( i%2 == 1)
{
sum += 1;
++cnt;
}
}
avg = 1.0*sum / cnt;
printf("sum = %d\n",sum);
printf("cnt = %d\n",cnt);
printf("avg = %f\n",avg);
return 0;
}
输出结果是
sum = 50
cnt = 50
avg = 1.000000
sum铁定错了但是我找不到哪里有问题T T,求指教啊