Kotlin Program to Find Factorial of a Number Using Recursion

Kotlin Program to Find Factorial of a Number Using Recursion: The factorial of a negative number doesn’t exist. And the factorial of 0 is 1.You will learn to find the factorial of a number using recursion in this example.

Kotlin Program to Find Factorial of a Number Using Recursion

Source Code

fun main(args: Array<String>) {
    val num = 6
    val factorial = multiplyNumbers(num)
    println("Factorial of $num = $factorial")
}

fun multiplyNumbers(num: Int): Long {
    if (num >= 1)
        return num * multiplyNumbers(num - 1)
    else
        return 1
}

Output