å帰
å¤æ°ããã¼ã«ã«ã§ãªãã£ãããgotoã使ããã¦ããã®ãæ°ã«å ¥ããªãå ´åã¯ããã£ã±ãå帰ã§ãããããããããéä¹ã®ä¾ãè¦ã¦ã¿ã¾ãããã
@echo off call :factorial %1 echo %ERRORLEVEL% exit /b 0 :factorial setlocal if %1 == 0 exit /b 1 set /a i = %1 - 1 call :factorial %i% set /a n = %1 * %ERRORLEVEL% exit /b %n%
>factorial.bat 10 3628800
factorialããfactorialãå¼ã³åºãã¦ãã¾ããç°¡åã§ãããããã§ãã®åé¡ã«ã¤ãã¦ãç°¡åã«æ¸ãã¾ãã
@echo off set /a N = 1000 set /a M = N - 1 set /a s = 0 for /L %%i in (1, 1, %M%) do call :sum %%i echo %s% exit /b 0 :sum setlocal call :is_valid %1 if %ERRORLEVEL% == 1 set /a s += %1 exit /b 0 :is_valid setlocal set /a r3 = %1 %% 3 if %r3% == 0 exit /b 1 set /a r5 = %1 %% 5 if %r5% == 0 exit /b 1 exit /b 0
ç°å¢ã«ãããã§ããããã1000ãããã®æ·±ããªã大ä¸å¤«ã®ããã§ãã