Magic squares of odd order: Difference between revisions

Magic squares of odd order in BASIC-256
m (→‎{{header|Perl}}: delete empty markup)
(Magic squares of odd order in BASIC-256)
Line 890:
190 NEXT
200 PRINT "The magic number is:";N*(N^2+1)/2</syntaxhighlight>
 
=={{header|BASIC256}}==
{{trans|Liberty BASIC}}
<syntaxhighlight lang="freebasic">arraybase 1
global m
 
call magicSquare(5)
call magicSquare(17)
end
 
subroutine magicSquare(n)
redim m(n,n)
inc = 1
cont = 1
row = 1
col = (n+1) / 2
while cont <= n*n
m[row,col] = cont
cont += 1
if inc < n then
inc += 1
row -= 1
col += 1
if row <> 0 then
if col > n then col = 1
else
row = n
end if
else
inc = 1
row += 1
end if
end while
call printSquare(n)
end subroutine
 
subroutine printSquare(n)
#Arbitrary limit to fit width of A4 paper
if n < 23 then
print
print n; " x "; n; " Magic Square --- ";
print "Magic constant is "; int((n*n+1)/2*n)
for row = 1 to n
for col = 1 to n
print rjust(string(m[row,col]),4);
next col
#print
print
next row
else
print "Magic Square will not fit on one sheet of paper."
end if
end subroutine</syntaxhighlight>
{{out}}
<pre>5 x 5 Magic Square --- Magic constant is 65
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
 
17 x 17 Magic Square --- Magic constant is 2465
155 174 193 212 231 250 269 288 1 20 39 58 77 96 115 134 153
173 192 211 230 249 268 287 17 19 38 57 76 95 114 133 152 154
191 210 229 248 267 286 16 18 37 56 75 94 113 132 151 170 172
209 228 247 266 285 15 34 36 55 74 93 112 131 150 169 171 190
227 246 265 284 14 33 35 54 73 92 111 130 149 168 187 189 208
245 264 283 13 32 51 53 72 91 110 129 148 167 186 188 207 226
263 282 12 31 50 52 71 90 109 128 147 166 185 204 206 225 244
281 11 30 49 68 70 89 108 127 146 165 184 203 205 224 243 262
10 29 48 67 69 88 107 126 145 164 183 202 221 223 242 261 280
28 47 66 85 87 106 125 144 163 182 201 220 222 241 260 279 9
46 65 84 86 105 124 143 162 181 200 219 238 240 259 278 8 27
64 83 102 104 123 142 161 180 199 218 237 239 258 277 7 26 45
82 101 103 122 141 160 179 198 217 236 255 257 276 6 25 44 63
100 119 121 140 159 178 197 216 235 254 256 275 5 24 43 62 81
118 120 139 158 177 196 215 234 253 272 274 4 23 42 61 80 99
136 138 157 176 195 214 233 252 271 273 3 22 41 60 79 98 117
137 156 175 194 213 232 251 270 289 2 21 40 59 78 97 116 135</pre>
 
=={{header|Batch File}}==
2,148

edits