kotlin Program to find Factorial of a Given Number : In this program, you’ll learn to find the factorial of a number using for and while loop in Kotlin. You’ll also learn to use ranges to solve this problem.
kotlin Program to find Factorial of a Given Number
Source Code
fun main(args: Array<String>) {
val num = 10
var factorial: Long = 1
for (i in 1..num) {
// factorial = factorial * i;
factorial *= i.toLong()
}
println("Factorial of $num = $factorial")
}
Output of Program