Sum of squares: Difference between revisions

Added Algol 60 sample - using Jensen's Device
(→‎{{header|ALGOL W}}: Added an alternative solution using Jensen's Device)
(Added Algol 60 sample - using Jensen's Device)
Line 249:
0
4.5</pre>
 
=={{header|ALGOL 60}}==
{{works with|GNU Marst|Any - tested with release 2.7}}
Using [[Jensen's Device]].
<syntaxhighlight lang="algol60">
begin
integer i;
integer array A[ 1 : 5 ];
real procedure sum (i, lo, hi, term);
value lo, hi;
integer i, lo, hi;
real term;
comment term is passed by-name, and so is i;
begin
real temp;
temp := 0;
for i := lo step 1 until hi do
temp := temp + term;
sum := temp
end;
comment initialie A;
for i := 1 step 1 until 5 do A[i] := i;
comment note the correspondence between the mathematical notation and the call to sum;
outreal(1, sum (i, 1, 5, A[i] * A[i]))
end
</syntaxhighlight>
 
=={{header|ALGOL 68}}==
3,026

edits