求1到100之间奇数的平均值? 大家写的怎么样.
自己琢磨着写的可以运行,不知道怎么样,哪里需要改进。# include <stdio.h>
int main(void)
{
int i;
int sum = 0;
int m;
int y = 0;
for(i = 1; i <= 100; ++i)
{
if(i%2 == 0)
{
sum = sum;
}
else
{
sum = sum+i;
}
}
for(m = 1; m <= 100; ++m)
{
if(m % 2 == 0)
{
y = y;
}
else
{
y = y + 1;
}
}
sum = sum / y;
printf("sum = %d\n",sum);
return 0;
}