백준 - 10872 팩토리얼
문제
10872 팩토리얼
답
kotlin code
1
2
3
4
5
6
7
8
9
10
11
12
13
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)
}
This post is licensed under CC BY 4.0 by the author.