Magic squares of doubly even order: Difference between revisions

(→‎{{header|ALGOL 60}}: Section added)
Line 115:
57 58 6 5 4 3 63 64
magic constant= 260
</pre>
 
=={{header|ALGOL 60}}==
{{works with|A60}}
<lang algol60>begin
comment Magic squares of doubly even order - 10/02/2021;
integer array pattern[1:4,1:4];
integer n, r, c, s, m, i, b, t;
n:=8;
for r:=1 step 1 until 4 do
for c:=1 step 1 until 4 do
pattern[r,c]:=if
((c=1 or c=4) and (r=1 or r=4)) or
((c=2 or c=3) and (r=2 or r=3)) then 1 else 0;
s:=n*n; m:=n div 4;
outstring(1,"magic square -- n ="); outinteger(1,n); outstring(1,"\n");
i:=0;
for r:=1 step 1 until n do begin
for c:=1 step 1 until n do begin
b:=pattern[(r-1) div m+1,(c-1) div m+1];
if b=1 then t:=i+1 else t:=s-i;
if t less 10 then outstring(1," ");
outinteger(1,t);
i:=i+1
end;
outstring(1,"\n")
end;
outstring(1,"magic constant ="); outinteger(1,(s+1)*n div 2)
end </lang>
{{out}}
<pre>
magic square -- n = 8
1 2 62 61 60 59 7 8
9 10 54 53 52 51 15 16
48 47 19 20 21 22 42 41
40 39 27 28 29 30 34 33
32 31 35 36 37 38 26 25
24 23 43 44 45 46 18 17
49 50 14 13 12 11 55 56
57 58 6 5 4 3 63 64
magic constant = 260
</pre>
 
1,392

edits