My bet is that you want something fast, otherwise you already have your answer. Sum all numbers that you already have by the length of the array you already have. This is very straightforward.
However sometimes you cannot know if the array will be bounded, it can be infinite, such as the data coming from a microphone. The suggestion of the moving average is good in this case, it means that you have to take the last x values from the array and calculate the average on those values only. The algorithm and the time required to compute the result stays the same whether you have x values or 1000x values.
edit :
the x vs 1000x comes from algo complexity. Suppose that you sum 5 numbers, that is 5 operations, then you divide by 5, another operation for a total of 6 ( for the sake of the example we'll assume that they all take the same computer time but in reality dividing is slow compared to adding ). If you take the same code but with 1000 numbers, you do 1001 operations which is going to take much more time than in the first case!
With the "moving average", you always take a fixed number of numbers so your algo takes a fixed amount of time to execute no matter if you have 5 or 1000 numbers.
Moving average is just a fancy wording to say that you do not take the same numbers in your array from one time to another. Imagine the following array :
int x = { 1, 4, 6, 3, 1 };
int arrayLength = 5;
Then the average of this array will be
int runningTotal = 0;
for(int i = 0; i < arrayLength; i++)
{
runningTotal += x[i];
}
double average = runningTotal / arrayLength
The moving average of 3 values would be
int movingLength = 3;
int runningTotal = 0;
for(int i = 0; i < movingLength; i++)
{
runningTotal += x[arrayLength - i - 1];
}
double average = runningTotal / movingLength;
So the first values in the array are not part of the calculation when the array grows.