Factorial of a Number
EasyNumbers & Math
The problem
Compute the factorial of a number n (the product of all integers from 1 to n).
Sample input
5
Sample output
120Show the solution · 8 languages
fun factorial(n: Int): Long {
var result = 1L
for (i in 2..n) result *= i
return result
}
fun main() {
println(factorial(5))
}