Created
June 20, 2021 06:58
-
-
Save Aditi3/d47e39de663521a8c1e5446367328809 to your computer and use it in GitHub Desktop.
Factorial program in swift using function
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 { | |
| var fact = 1 | |
| for n in 1...number { | |
| fact = fact * n | |
| } | |
| return fact | |
| } | |
| let result = factorial(10) | |
| print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment