Task[edit]
Write a program to find the mean (arithmetic average) of a numeric vector.

In case of a zero-length input, since the mean of an empty set of numbers is ill-defined, the program may choose to behave in any way it deems appropriate, though if the programming language has an established convention for conveying math errors or undefined values, it's preferable to follow it.

See also
Tasks for calculating statistical measures



in one go
moving (sliding window)
moving (cumulative)

Mean
Arithmetic

Statistics/Basic
Averages/Arithmetic mean
Averages/Pythagorean means


Averages/Simple moving average




Geometric

Averages/Pythagorean means




Harmonic

Averages/Pythagorean means




Quadratic

Averages/Root mean square




Circular

Averages/Mean angle
Averages/Mean time of day




Median

Averages/Median




Mode

Averages/Mode




Standard deviation

Statistics/Basic



Cumulative standard deviation






ArithmeticMean:		PHA
			TYA
			PHA		;push accumulator and Y register onto stack
 
 
			LDA #0
			STA Temp
			STA Temp+1	;temporary 16-bit storage for total
 
			LDY NumberInts	
			BEQ Done	;if NumberInts = 0 then return an average of zero
 
			DEY		;start with NumberInts-1
AddLoop:		LDA (ArrayPtr),Y
			CLC
			ADC Temp
			STA Temp
			LDA Temp+1
			ADC #0
			STA Temp+1
			DEY
			CPY #255
			BNE AddLoop
 
			LDY #-1
DivideLoop:		LDA Temp
			SEC
			SBC NumberInts
			STA Temp
			LDA Temp+1
			SBC #0
			STA Temp+1
			INY
			BCS DivideLoop
 
Done:			STY ArithMean	;store result here
			PLA		;restore accumulator and Y register from stack
			TAY
			PLA
			RTS		;return from routine