Advertisement
IcarusLives

Factorial Function

Feb 18th, 2017
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 0.61 KB | None | 0 0
  1. ::---------------------------------------------------------------------------------------
  2. ::  Get the factorial of a number
  3. ::
  4. :: call :factorial 7 RETURNVAR
  5. :: echo %RETURNVAR%
  6. ::---------------------------------------------------------------------------------------
  7. :factorial
  8.     setlocal
  9.         set "out=1"
  10.        
  11.         for /l %%a in (%~1,-1,1) do set /a "out*=%%a"
  12.         if %~1 equ 0 set "out=1"
  13.        
  14.         (endlocal
  15.             if "%~2" neq "" ( set "%~2=%out%" ) else echo %out%
  16.         )
  17. goto :eof
  18. ::---------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement