Question: Can some one please help me on this issue as I have spent time going around it without making any headway.
I have data in an array of size say 3O. 

1. I want to take the first five elements of the array, find their mean value. Store the value in another array
2. Then move to the second element of the array,from their find the mean value of the 5 succeeding elements.store the value in the array as above.
3. Then wove to the 3rd element,do the same thing above till the last element which is 30 in this case.

```
float tabdata[] = {1,2,3,4,...,30};
char *store;
float sum;

for(int j=0;j<tabdata[30-1];j++)
   sum += tabdata[j];
if (j=5)
{
   float mean= sum/5;
   store[j]=mean;
   sum=0;
   for(i=j;i>tabdata[30-1];i++)
       sum +=tabdata[i];

```

if (j=5)
 ---
 ----
 ....need help to complete this loop please.

Answer: 
You can fix up the sum as you go:

```
#include <stdlib.h>
#include <stdio.h>

int main()
{
    float tabdata[] = {1,1.5,1.8, 2, 3, 4, 5,6,7,8,9,10,11,12,13,14,15,161,7,18,19,20,21,30};
    float* result;
    float sum;
    int count = sizeof(tabdata)/sizeof(tabdata[0]);
    int i;

    result = (float *)malloc((count - 4) * sizeof(float));
    /* Initialise with the first five elements */
    for (i=0;i<5;i++)
    {
        sum += tabdata[i];
    }
    result[0] = sum / 5.0;

    for (i=5;i<count;i++)
    {
        sum -= tabdata[i-5];
        sum += tabdata[i];
        result[i-4] = sum / 5.0;
    }

    for (i=0;i<count-4;i++)
    {
        printf("%f\t%f\n",tabdata[i],result[i]);
    }
    for (;i<count;i++)
    {
        printf("%f\n",tabdata[i]);
    }

    free(result);
}

```
I think that what you might want to use is the modulus operator (%) which will give you the rest of the division. You will get something like this:

```
if ((j+1) % 5 == 0)
{
   float mean= sum/5;
   store[j/5]=mean;
   sum=0;
}

```

This way, at every 5 iterations, the code will be executed.