Averages/Pythagorean means: Difference between revisions

m
→‎[[Averages/Pythagorean means#ALGOL 68]]: translation of the C implementation.
m (→‎[[Averages/Pythagorean means#ALGOL 68]]: translation of the C implementation.)
Line 40:
trace("Harmonic: ", harmonicMean(list));
</lang>
=={{header|ALGOL 68}}==
{{trans|C}}
 
{{wont work with|ALGOL 68|Standard - argc and argv implementation dependent}}
 
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
 
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - argc and argv implementation dependent}}
<lang algol68>main: (
INT count:=0;
LONG REAL f, sum:=0, prod:=1, resum:=0;
 
FORMAT real = $g(0,4)$; # prefered real format #
 
FILE fbuf; STRING sbuf; associate(fbuf,sbuf);
 
BOOL opts := TRUE;
 
FOR i TO argc DO
IF opts THEN # skip args up to the -- token #
opts := argv(i) NE "--"
ELSE
rewind(fbuf); sbuf := argv(i); get(fbuf,f);
count +:= 1;
sum +:= f;
prod *:= f;
resum +:= 1/f
FI
OD;
printf(($"c: "f(real)l"s: "f(real)l"p: "f(real)l"r: "f(real)l$,count,sum,prod,resum));
printf(($"Arithmetic mean = "f(real)l$,sum/count));
printf(($"Geometric mean = "f(real)l$,prod**1/count));
printf(($"Harmonic mean = "f(real)l$,count/resum))
)</lang>
Run command with arguments<pre>
a68g Pythagorean_means.a68 -- 1 2 3 4 5 6 7 8 9 10
</pre>
Output:
<pre>
c: 10.0000
s: 55.0000
p: 3628800.0000
r: 2.9290
Arithmetic mean = 5.5000
Geometric mean = 362880.0000
Harmonic mean = 3.4142
</pre>
 
=={{header|C}}==
<lang c>#include <stdio.h>