Factorial of a number in Swift

Swift code to find the Factorial of a given Number.

Source code :



var number: Int = 5 // Change the number here 

var fact: Int = 1

var n: Int = number + 1

for i in 1..<n{
    
    fact = fact * i
    
}



print("Factorial of ",number," is: ", fact)


Output :

Factorial of  5  is:  120

Output :


                

Comments :