凑热闹 马步的
修改前面的set ".!h!-!m!=1"这句放在FOR里面
- @echo off
- :start
- setlocal enabledelayedexpansion
- echo.&set /p n= 请输入一个奇数 &cls
- set /a m=n/2+1,c=n*n,he=(n*n+1)*n/2
- echo !n! 阶幻方各行,列以及对角线相加的和为: %he%&echo.
- for /l %%i in (1 1 !c!) do (
- set/a i=%%i%%n
- if !i! equ 1 (set/a h=h%%n+1) else set/a h=h%%n+2,m=m%%n+1
- if !h! gtr !n! set h=1
- set ".!h!-!m!=%%i"
- )
- for %%i in (0 1 10) do if not "!c:~%%i,1!"=="" set /a j=%%i+2&set "k=!k! "
- for /l %%a in (1 1 !n!) do (
- set "var="
- for /l %%b in (1 1 !n!) do (
- set "str=!k!!.%%a-%%b!"
- set "var=!var! !str:~-%j%!"
- )
- echo.!var:~1!
- )
- pause
- endlocal&goto start
复制代码
[ 本帖最后由 terse 于 2009-4-6 11:07 编辑 ] |