Magic squares of odd order: Difference between revisions

Add BCPL
(Add APL)
(Add BCPL)
Line 964:
10 12 19 21 3
11 18 25 2 9</pre>
 
=={{header|BCPL}}==
{{trans|C}}
<lang bcpl>get "libhdr"
 
let cell(n, x, y) = f(n, n-x-1, y)*n + f(n, x, y) + 1
and f(n, x, y) = (x + y*2 + 1) rem n
 
let magic(n) be
$( writef("Magic square of order %N with constant %N:*N", n, (n*n+1)/2*n)
for y = 0 to n-1
$( for x = 0 to n-1 do writed(cell(n, x, y), 4)
wrch('*N')
$)
wrch('*N')
$)
 
let start() be for n = 1 to 7 by 2 do magic(n)</lang>
{{out}}
<pre>Magic square of order 1 with constant 1:
1
 
Magic square of order 3 with constant 15:
2 9 4
7 5 3
6 1 8
 
Magic square of order 5 with constant 65:
2 23 19 15 6
14 10 1 22 18
21 17 13 9 5
8 4 25 16 12
20 11 7 3 24
 
Magic square of order 7 with constant 175:
2 45 39 33 27 21 8
18 12 6 49 36 30 24
34 28 15 9 3 46 40
43 37 31 25 19 13 7
10 4 47 41 35 22 16
26 20 14 1 44 38 32
42 29 23 17 11 5 48</pre>
 
=={{header|Befunge}}==
2,114

edits