Averages/Arithmetic mean: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1,016: | Line 1,016: | ||
] |
] |
||
) displayNl.</lang> |
) displayNl.</lang> |
||
=={{header|SNOBOL4}}== |
|||
{{works with|Macro Spitbol}} |
|||
{{works with|Snobol4+}} |
|||
{{works with|CSnobol}} |
|||
<lang SNOBOL4> define('avg(a)i,sum') :(avg_end) |
|||
avg i = i + 1; sum = sum + a<i> :s(avg) |
|||
avg = 1.0 * sum / prototype(a) :(return) |
|||
avg_end |
|||
* # Fill arrays |
|||
str = '1 2 3 4 5 6 7 8 9 10'; arr = array(10) |
|||
loop i = i + 1; str len(p) span('0123456789') . arr<i> @p :s(loop) |
|||
empty = array(1) ;* Null vector |
|||
* # Test and display |
|||
output = '[' str '] -> ' avg(arr) |
|||
output = '[ ] -> ' avg(empty) |
|||
end</lang> |
|||
Output: |
|||
<pre>[1 2 3 4 5 6 7 8 9 10] -> 5.5 |
|||
[ ] -> 0.</pre> |
|||
=={{header|Standard ML}}== |
=={{header|Standard ML}}== |