我的其中一个值总是,显示不出,不知道哪里出了问题,求解。
# include <stdio.h>int main(void)
{
int i;
int sum = 0;
int cnt = 0;
double avg;
for (i=1; i<101; ++i)
{
if (i%2 == 1)
{
sum += i;
++cnt;
}
}
avg = sum / cnt;
printf("sum = %d\n", sum);
printf("cnt = %d\n", cnt);
printf("avg = %d\n", avg);
return 0;
}
/*
运行结果为:sum = 2500
cnt = 50
avg = 0》》》》就是这里为什么会是零???
Press any key to continue
Press any key to continue
*/