Kotlin Program to Find Factorial of a Number Using Recursion

Kotlin Program to Find Factorial of a Number Using Recursion: Write a program to find factorial of a given number is a common kotlin program asked in an interview with freshers.The factorial of a non-negative integer n is the product of all positive integers less than or equal to n.

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