Even-sum
Subject description:
Has a length of n- (n-<= 100) the number of columns, is defined as the number of columns from 2 starts incrementing 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 2Sample Output
3 6 3 7
By the answer:
#include <stdio.h>
int main(){
int n,m;
while(scanf("%d %d",&n,&m)!=EOF){
for(int i=1;i<=n;){
int sum=0,count=0;
for(int j=1;j<=m&&i<=n;j++){
sum+=2*i;
count++; //统计个数
i++;
}
printf("%d",sum/count);
if(i<=n){
printf(" "); //平均值之间需要空格隔开
}
}
printf("\n"); //换行一定要!
}
return 0;
}