Averages/Arithmetic mean: Difference between revisions
Content added Content deleted
Line 31: | Line 31: | ||
3.83333 |
3.83333 |
||
0.00000 |
0.00000 |
||
=={{header|ALGOL 68}}== |
|||
{{trans|C}} |
|||
{{works with|ALGOL 68|Standard - no extensions to language used}} |
|||
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386}} |
|||
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386 - note that some necessary LONG REAL are missing from ELLA's library.}} |
|||
<pre> |
|||
PROC mean = (REF[]REAL p)REAL: |
|||
# Calculates the mean of qty REALs beginning at p. # |
|||
IF LWB p > UPB p THEN 0.0 |
|||
ELSE |
|||
REAL total := 0.0; |
|||
FOR i FROM LWB p TO UPB p DO total +:= p[i] OD; |
|||
total / (UPB p - LWB p + 1) |
|||
FI; |
|||
main:( |
|||
[6]REAL test := (1.0, 2.0, 5.0, -5.0, 9.5, 3.14159); |
|||
print((mean(test),new line)) |
|||
) |
|||
</pre> |
|||
=={{header|APL}}== |
=={{header|APL}}== |