Averages/Arithmetic mean: Difference between revisions
Content deleted Content added
added Cobra example |
|||
Line 351: | Line 351: | ||
(/ (reduce + sq) length))) |
(/ (reduce + sq) length))) |
||
)</lang> |
)</lang> |
||
=={{header|Cobra}}== |
|||
<lang cobra> |
|||
class Rosetta |
|||
def mean(ns as List<of number>) as number |
|||
if ns.count == 0 |
|||
return 0 |
|||
else |
|||
sum = 0.0 |
|||
for n in ns |
|||
sum += n |
|||
return sum / ns.count |
|||
def main |
|||
print "mean of [[]] is [.mean(List<of number>())]" |
|||
print "mean of [[1,2,3,4]] is [.mean([1.0,2.0,3.0,4.0])]" |
|||
</lang> |
|||
Output: |
|||
<pre> |
|||
mean of [] is 0 |
|||
mean of [1, 2, 3, 4] is 2.5 |
|||
</pre> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |