Skip to content

Instantly share code, notes, and snippets.

@milanpanchal
Last active May 7, 2020 10:27
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 milanpanchal/3509ba07e0ecc2f03290021419fc3089 to your computer and use it in GitHub Desktop.
Save milanpanchal/3509ba07e0ecc2f03290021419fc3089 to your computer and use it in GitHub Desktop.
Find factorial of the int number in swift
func factorial(of number: Int) -> Int {
if number == 1 {
return 1
} else {
return number * factorial(of: number - 1)
}
}
let val = 5
let result = factorial(of: val)
print("The factorial of \(val) is \(result)")
// prints: The factorial of 5 is 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment