Last active
May 7, 2020 10:27
-
-
Save milanpanchal/3509ba07e0ecc2f03290021419fc3089 to your computer and use it in GitHub Desktop.
Find factorial of the int number in swift
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
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