Created
February 14, 2012 21:56
-
-
Save AndreLouisCaron/1830848 to your computer and use it in GitHub Desktop.
Recursive factorial function using Windows Batch Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
call:factorial "%~1" | |
echo result: %ErrorLevel% | |
exit /b 0 | |
:factorial | |
if "%~1" LEQ "2" ( | |
set ErrorLevel=%~1 | |
exit /b 0 | |
) | |
set /a next=%~1 - 1 | |
call:factorial %next% | |
set /a ErrorLevel=%~1 * %ErrorLevel% | |
exit /b 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist was created to complement the iterative factorial version submitted to the "Factorial Algorithms in different languages" on StackOverflow.