- @echo off&setlocal enabledelayedexpansion
- set /p n=请输入数字(1-9)
- set /a nn=n*n
- for /l %%i in (1,1,%nn%) do (
- set "a=%%i"&set /a v+=1
- if !a! lss 10 set "a= !a!"
- set /p=!a! <nul
- if !v! equ %n% set "v=0"&echo.
- )
- pause>nul
复制代码
还可减少一个变量:
- @echo off&setlocal enabledelayedexpansion
- set /p n=请输入数字(1-9)
- set /a nn=n*n
- for /l %%i in (1,1,%nn%) do (
- set /a v+=1
- if %%i lss 10 (
- set /p= %%i <nul
- ) else (
- set /p=%%i <nul
- )
- if !v! equ %n% set "v=0"&echo.
- )
- pause>nul
复制代码
[ 本帖最后由 batman 于 2008-8-28 10:31 编辑 ] |