Averages/Pythagorean means: Difference between revisions
Content added Content deleted
(Added solution for Action!) |
|||
Line 44: | Line 44: | ||
4.52873 |
4.52873 |
||
3.41417 |
3.41417 |
||
</pre> |
|||
=={{header|Action!}}== |
|||
{{libheader|Action! Tool Kit}} |
|||
<lang Action!>INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit |
|||
PROC InverseI(INT a,result) |
|||
REAL one,x |
|||
IntToReal(1,one) |
|||
IntToReal(a,x) |
|||
RealDiv(one,x,result) |
|||
RETURN |
|||
PROC ArithmeticMean(INT ARRAY a INT count REAL POINTER result) |
|||
INT i |
|||
REAL x,sum,tmp |
|||
IntToReal(0,sum) |
|||
FOR i=0 TO count-1 |
|||
DO |
|||
IntToReal(a(i),x) |
|||
RealAdd(sum,x,tmp) |
|||
RealAssign(tmp,sum) |
|||
OD |
|||
IntToReal(count,tmp) |
|||
RealDiv(sum,tmp,result) |
|||
RETURN |
|||
PROC GeometricMean(INT ARRAY a INT count REAL POINTER result) |
|||
INT i |
|||
REAL x,prod,tmp |
|||
IntToReal(1,prod) |
|||
FOR i=0 TO count-1 |
|||
DO |
|||
IntToReal(a(i),x) |
|||
RealMult(prod,x,tmp) |
|||
RealAssign(tmp,prod) |
|||
OD |
|||
InverseI(count,tmp) |
|||
Power(prod,tmp,result) |
|||
RETURN |
|||
PROC HarmonicMean(INT ARRAY a INT count REAL POINTER result) |
|||
INT i |
|||
REAL x,sum,tmp |
|||
IntToReal(0,sum) |
|||
FOR i=0 TO count-1 |
|||
DO |
|||
InverseI(a(i),x) |
|||
RealAdd(sum,x,tmp) |
|||
RealAssign(tmp,sum) |
|||
OD |
|||
IntToReal(count,tmp) |
|||
RealDiv(tmp,sum,result) |
|||
RETURN |
|||
PROC Main() |
|||
BYTE i |
|||
INT ARRAY a=[1 2 3 4 5 6 7 8 9 10] |
|||
REAL result |
|||
Put(125) PutE() ;clear screen |
|||
ArithmeticMean(a,10,result) |
|||
Print("Arithmetic mean=") PrintRE(result) |
|||
GeometricMean(a,10,result) |
|||
Print(" Geometric mean=") PrintRE(result) |
|||
HarmonicMean(a,10,result) |
|||
Print(" Harmonic mean=") PrintRE(result) |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Pythagorean_means.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
|||
Arithmetic mean=5.5 |
|||
Geometric mean=4.52872861 |
|||
Harmonic mean=3.41417153 |
|||
</pre> |
</pre> |
||