Anonymous user
Averages/Pythagorean means: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, used a template for the output sections.
(→{{header|Kotlin}}: kotlin/js compatability, harmonic mean: reduce to fold since first element is not divided) |
m (→{{header|REXX}}: added/changed whitespace and comments, used a template for the output sections.) |
||
Line 2,817:
numeric digits 20 /*use a little extra for the precision.*/
parse arg n . /*obtain the optional argument from CL.*/
if n=='' | n=="," then n=
sum= 0; prod= 1; rSum=
$=; do #=1 for n;
sum = sum +
prod= prod *
rSum= rSum +
end /*#*/
say ' list ='$ /*display the list of numbers used. */
say 'Amean =' sum / n /*calculate & display arithmetic mean.*/
say 'Gmean =' Iroot(prod, n) /* " " " geometric " */
say 'Hmean =' n / rSum /* " " " harmonic " */
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
Iroot: procedure; parse arg x 1 ox, y 1 oy
if x=0 | x=1 | y=1 then return x
if x<0 & y//2==0 then return
x= abs(x); y= abs(y);
oDigs= digits(); a= oDigs + 5
g= (x+1) / y*
_= format( (m*g*gm + x)
if _=g | _=og then leave
end /*forever*/
numeric digits oDigs; return
▲IrootErr: say '***error*** (from Iroot): root' y "can't be even if 1st argument is < 0."
▲'''output''' using the default inputs:
<pre>
list = 1 2 3 4 5 6 7 8 9 10
|