编写1到100的奇数和,偶数和,平均值。。。
本人新手,纯自己想的。。请各位高手多多指点求奇数与偶数和
# include <stdio.h>
int main (void)
{
int a = 1, b = 2;
int suma = 0, sumb = 0;
for (a=1,b=2; a<=100,b<=100; a+=2,b+=2 )
{
suma = suma + a, sumb =sumb + b;
}
printf("suma=%d\n sumb=%d\n",suma,sumb);
return 0;
}
--------------------------------------------------------------------------------------------------------
求平均值
# include <stdio.h>
int main (void)
{
int a = 1;
int suma = 0, sumb = 0;
for(a=1; a<=100; a+=2)
{
suma = suma + a, sumb = sumb + 1;
}
suma = suma / sumb;
printf("suma=%d\n",suma);
return 0;
}