本帖最后由 linqing8 于 2011-4-27 13:01 编辑
我的杨辉三角,刚费老劲做出来,还未精简:- @echo off
- del num.txt
- setlocal ENABLEDELAYEDEXPANSION
- set /p n=请输入层数,不要超过30.
- for /l %%i in (1,1,%n%) do (
- set ln=%%i
- set a1=1
- set a!ln!=1
- set num=1
- if %%i geq 3 (
- set /a r1=2
- set /a r2=!ln!-1
- for /l %%j in (!r1!,1,!r2!) do (
- set col=%%j
- set /a r3=%%j-1
- set /a r4=!ln!-2
- call :aaa
- )
- )
- if !ln! geq 2 for /l %%m in (2,1,!ln!) do (set num=!num! !a%%m!)
- echo !num! >> num.txt
- )
- start num.txt
- goto :eof
- :aaa
- for /f "skip=%r4% tokens=%r3%,%col%" %%k in (num.txt) do set /a a%col%=%%l+%%k
复制代码
|