문제
10872 팩토리얼
답
kotlin code
fun main() {
q10872()
}
fun q10872() {
val n = readln().toInt()
println(factorial(n))
}
tailrec fun factorial(n:Int, acc:Int = 1): Int = when(n){
0 -> acc
else -> factorial(n - 1, acc * n)
}
fun main() {
q10872()
}
fun q10872() {
val n = readln().toInt()
println(factorial(n))
}
tailrec fun factorial(n:Int, acc:Int = 1): Int = when(n){
0 -> acc
else -> factorial(n - 1, acc * n)
}