在批处理目录下生成文件rusult.txt,内如如下:
:@echo off
setlocal ENABLEDELAYEDEXPANSION
for /l %%i in (1,1,9) do (
call:func %%i + str
>>rusult.txt echo !str!
)
>>rusult.txt echo.
for /l %%i in (1,1,9) do (
call:func %%i - str
>>rusult.txt echo !str!
)
>>rusult.txt echo.
for /l %%i in (1,1,9) do (
call:func %%i * str
>>rusult.txt echo !str!
)
pause
goto:eof
::///
:func
set "tmp=%1"
set "symbol=%2"
for /l %%j in (1,1,9) do (
if %%j GTR !tmp! (goto:eof)
if "!symbol!" equ "+" (set /a sum=%tmp%+%%j)
if "!symbol!" equ "-" (set /a sum=%tmp%-%%j)
if "!symbol!" equ "*" (set /a sum=%tmp%*%%j)
if %%j equ 1 (
set str=!tmp!!symbol!%%j=!sum!
) else (
set str=!str! !tmp!!symbol!%%j=!sum!
)
)
set %3=!str!
goto:eof