sum them all up and divide by the size of the array. For example
int a[3] = {2,4,6};
The sum is 2+4+6 = 12
The average is 12/3 = 4
Ancient Dragon
Retired & Loving It
30,043 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
Think about how you add up. Suppose I ask you to add the
number in the series 2,6,9. you don't go let me put the numbers into
an array. you simply keep a running total,
So in your case
start a total
total=0
then IF the number is >0 add to total
divide total by the number of >0 numbers (or 42 ;-)
Just because it is programming it doesn't mean that you can forget you kindergarden maths.
StuXYZ
Practically a Master Poster
680 posts since Nov 2008
Reputation Points: 760
Solved Threads: 138