Home > Back-end >  ZCMU 1318 even sum
ZCMU 1318 even sum

Time:12-20

The Description
There is a length of n (n<=100) series, the series is defined as increasing from 2 order even number (tolerance is 2) arithmetic progression, now require you to in accordance with the order number calculated an average per m, if the lack of m, with the actual number of averaging, programming the average output sequence,

Input
How much input data set, a line, each group contains two positive integer n and m, n and m as described above, the meaning of

The Output
For each group of input data, the average output a sequence, each set of output a line

The Sample Input
3 2
4 2
The Sample Output
3 6
3 7
Code:
#include
using namespace std;
Int n, m;
Int sl (int x, int y)
{
Int s=0, sum=0;
Int countn=0;
for(int i=1; i<=x; I++)
{
S=s + 2;
Sum=sum + s;
If (I % y==0 & amp; & Countn==0)
{
Printf (" % d ", sum/y);
Countn++;
Sum=0;
}
Else if (I % y==0 & amp; & Countn!=0)
{
Printf (" % d ", sum/y);
Sum=0;
}
}
If (x % y!=0)
Printf (" % d ", sum/y) (x %);
printf("\n");
}
Int main ()
{
While (~ the scanf (" % d % d ", & amp; N, & amp; M))
{
Sl (n, m);
}
return 0;
}
  • Related