横竖两个数字塔的效果BAT批处理怎么写?

时间:2021-10-04 11:24:08

横竖两个数字塔的效果BAT批处理怎么写?
@echo off
for /l %%a in (0,1,1) do (
        for /l %%i in (0,1,9) do (
        for /l %%j in (0,1,%%i) do set /p=%%j<nul
        echo=
        )
)
pause

我这个BAT可以竖下来输出2个数字塔,
0
01
012
0123
01234
012345
0123456
01234567
012345678
0123456789
0
01
012
0123
01234
012345
0123456
01234567
012345678
0123456789
如果我想达到如下图的格式,横向的效果要怎么写呢?
0          0
01         01
012        012
0123       0123
01234      01234
012345     012345
0123456    0123456
01234567   01234567
012345678  012345678
0123456789 0123456789
---------------------------------------------------------------------
回复 1# battab
@echo off&setlocal enabledelayedexpansion
set "space=          "
for /l %%i in (0,1,9) do (
        set/a n=10-%%i,m=%%i-1
        for %%z in (!n!) do set t=!space:~,%%z!
        for /l %%j in (0,1,!m!) do set /p=%%j<nul
        set/p=%%i!t!<nul
        for /l %%j in (0,1,%%i) do set /p=%%j<nul
        echo,
)
pause
---------------------------------------------------------------------
@echo off & setlocal enabledelayedexpansion
for /l %%i in (0 1 9) do set "sp=!sp! "
for /l %%i in (0 1 9) do (
    set "s="
    for /l %%j in (0 1 %%i) do set "s=!s!%%j"
    set "str=!s!!sp!"
    echo,!str:~,11!!s!
)
pause
---------------------------------------------------------------------
继续发另类解:
@echo off
%1 cmd /v /c @%0 :|more /t11&pause&exit

for /f "delims=U" %%a in ('cmd /u /c echo 唉') do set "tab=%%a"
for /l %%a in (0 1 9) do set str=!str!%%a&echo !str!!tab!!str!
---------------------------------------------------------------------
这个好 mark一下 留着用.
学习了..
---------------------------------------------------------------------
这样简化
@echo off&setlocal enabledelayedexpansion
for /l %%i in (0 1 9) do set "sp=!sp! "
for /l %%i in (0 1 9) do (
    set "str=!str!%%i"
    echo !str!!sp:~%%i!!str!
)
pause
---------------------------------------------------------------------
我也给个自己写的,把第二个for的参数改下,横向的可以打印1,2,3,4,5,6........个数字塔
@echo off
for /l %%i in (0,1,9) do (
for /l %%j in (0,1,1) do (
for /l %%k in (0,1,10) do (
if %%k leq %%i (set /p =%%k<nul) else (set /p = <nul)
)
)
echo.
)
echo.
----------------------------------------------------------------
参考:http://bathome.net/thread-28624-1-2.html