• Home
  • About
    • Moon photo

      Moon

      개발자는 자고 싶다.

    • Learn More
    • Twitter
    • Facebook
    • Instagram
    • Github
    • Steam
  • Posts
    • All Posts
    • All Tags
  • Projects

백준 - 10872 팩토리얼

05 Jun 2022

Reading time ~1 minute

문제

10872 팩토리얼

screencaptures

답

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)
}


baekjoonkotlin코틀린백준브론즈수학구현조합론 Share Tweet +1