Created
June 20, 2021 07:01
-
-
Save Aditi3/1f96369e9b4da6bfb9c5d0784a1a8505 to your computer and use it in GitHub Desktop.
Factorial program in swift using recursion
This file contains hidden or 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
| import UIKit | |
| func factorial(number: Int) -> Int { | |
| // base case | |
| if number == 0 { // end the recursion | |
| return 1 | |
| } | |
| // recursive case | |
| return number * factorial(number: number - 1) | |
| } | |
| let result = factorial(number: 10) | |
| print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment