Skip to content

Instantly share code, notes, and snippets.

@Aditi3
Created June 20, 2021 07:01
Show Gist options
  • Select an option

  • Save Aditi3/1f96369e9b4da6bfb9c5d0784a1a8505 to your computer and use it in GitHub Desktop.

Select an option

Save Aditi3/1f96369e9b4da6bfb9c5d0784a1a8505 to your computer and use it in GitHub Desktop.
Factorial program in swift using recursion
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