バッチ処理でn階段の魔方陣を出力する
@echo off
:start
set /p n=Please input your odd integer:
set /a p=n%%2
if %p% equ 0 echo Input error!&&goto start
set /a i=%n%
set /a t=(%n%+1)/2
set /a a%t%_%n%=1,temp=1,m=n-1,p=n
:repeat
set /a p-=1
if %p% lss 0 goto array
for /l %%a in (1 1 %m%) do (
setlocal enabledelayedexpansion
if !t! gtr %n% set /a t=1
if !i! gtr %n% set /a i=1
set /a s=!t!+1,q=!i!+1
if !s! gtr %n% set /a s=1
if !q! gtr %n% set /a q=1
set /a a!s!_!q!=a!t!_!i!+1,t+=1,i+=1
set /a temp+=1
if !temp! equ %n% (
set /a temp=1,tmp=a!s!_!q!,q-=1,i-=1
if !q! equ 0 set /a q=n
set /a a!s!_!q!=tmp+1
goto repeat
)
)
pause
:array
echo Now behold the powerful Magic Sqaure^^!:
set /a a!t!_!n!=1
for /l %%c in (!n! -1 1) do (
for /l %%d in (1 1 !n!) do (
set /a result=a%%d_%%c
set /p=!result!