Problem Description
Has a length of n (n <= 100) the number of columns, is defined as the number of columns 2 increments from the start of the even-ordered, asks you to obtain a mean value according to the number per m order, if the last number is less than m, places The actual number averaged. The average output programmed sequence.
Input
A plurality of input data sets, each representing one line, comprising two positive integers n and m, n and m are the meanings described above.
Output
For each set of input data, it outputs a mean value sequence, each output per line.
Sample Input
3 2
4 2
Sample Output
3 6
3 7
#include<stdio.h>
void main()
{
int n,m,i,d,s,a;
while(scanf("%d%d",&n,&m)!=EOF)
{
s=0;//偶数总和
a=0;//偶数
for(i=1;i<=n;i++)
{
a=i*2;
s=s+a;
if(i%m==0)//判读i是否到达m个,满足m个以后进行后面操作
{
if(i==n)
{
printf("%d\n",s/m);
break;
}//如果i以及是最后一个数,那么就直接输出偶数总和除以m,并跳出来,注意换行符
printf("%d ",s/m);//否则就输出s/m,但不需要换行符
s=0;//将s清空,准备下一组m个偶数的求和
}
else if(i==n)//如果m比n要大,这时候i就等于了n
{
d=n%m;//求出余数 比如n=4,m=5;n%m=4,就相当于是m
printf("%d\n",s/d);
}
}
}
}