求1到100之间的奇数的和、奇数的个数、奇数和的平均值
具体实操:
/*
2021/12/21,10:46
目的:
求1到100之间的奇数的和、个数、平均值。
*/
#include <stdio.h>
int main(void)
{
int i;
int count = 0;
int sum = 0;
float average = 0.0;
for(i=1; i<101; ++i)
{
if(i%2 == 1)
{
sum += i;
++count;
}
}
average = 1.0*sum / count;
printf("sum = %d\n", sum);
printf("count = %d\n", count);
printf("average = %f\n", average);
return 0;