Use an algorithm that includes a counter and condition it to calculate an average whenever the counter reaches 3 or more; reset counter afterwards.
My assumption is that you are reading from a file.
counter=sum=number=0;
Loop
---read number
---counter++;//counting from 0 to 2; 3 == reset;
---if(counter>2)
------calculate average of sums;
------sum=0;//reset sum;
---else
------sum = sum + number;//The one read