printf("average = %d\n", average);为什么%d改为%f无法显示答案?
/*求1到100之间的奇数的平均值
*/
# include <stdio.h>
int main(void)
{
int i;
int sum1 = 0;
int sum2 = 0;
int average = 0;
for (i=1; i<=100; i+=2)
{
sum1 = sum1 + i;
sum2 = ++ sum2;
}
average = sum1 / sum2;
printf("average = %d\n", average);
return 0;
}
我把 printf("average = %d\n", average); 中 %d 改为 %f 无法显示答案;
怎么改才能让输出可以表示小数?