Anonymous user
Averages/Arithmetic mean: Difference between revisions
m
Spelling/grammar/aesthetics
(Added Java example.) |
m (Spelling/grammar/aesthetics) |
||
Line 1:
{{task}}
Write a program to find the mean (arithmetic average) of a numeric vector. The program should work on a zero-length vector (with an answer of 0).
=={{header|J}}==
Line 8 ⟶ 7:
mean=: +/ % #
That is, sum divided by the number of items.
mean 3 1 4 1 5 9
Line 18 ⟶ 17:
0.58243 0.402948 0.477066 0.511155
The computation can also be written as a loop.
mean1=: 3 : 0
|