Skip to content

Instantly share code, notes, and snippets.

@AndreLouisCaron
Created February 14, 2012 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreLouisCaron/1830848 to your computer and use it in GitHub Desktop.
Save AndreLouisCaron/1830848 to your computer and use it in GitHub Desktop.
Recursive factorial function using Windows Batch Files
@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
@AndreLouisCaron
Copy link
Author

This gist was created to complement the iterative factorial version submitted to the "Factorial Algorithms in different languages" on StackOverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment