求1到n之间的奇数和与奇数个数可以这样写吗?
# include <stdio.h># include <math.h>
int main ()
{
int i, j, n, m;
int sum = 0;
printf("请输入任意值,求1到任意值之间的奇数之和:\n");
scanf("%d",&j);
for(i=1; i<=j; i=i+2)
{
sum = sum + i;
}
printf("奇数之和sum=%d\n",sum);
n = sqrt(sum); //n个奇数之和sum=n*n
printf("奇数个数n=%d\n",n);
m = sum/n;
printf("奇数之和平均值m=%d\n",m);
return 0;
}