Average value of array: MLQ4

 

How can I get the average value of an array?

 int x[5];
 x[0]=3;
 x[1]=7;
 x[2]=4;
 x[3]=7;
 x[4]=9;
 Alert("The average value of x is: ");

 

 
hknight:

How can I get the average value of an array?

Add the elements,  divide by the number of elements . . .  isn't that how you calculate an average ?

int x[5];
 x[0]=3;
 x[1]=7;
 x[2]=4;
 x[3]=7;
 x[4]=9;

int ArrayIndex;
double ArraySum;

for(ArrayIndex = ArraySize(x) - 1; ArrayIndex >= 0; ArrayIndex--)
   ArraySum += x[ArrayIndex];

 Alert("The average value of x is: ", ArraySum/ArraySize(x));
 
Thanks. 
Reason: