Factorial of number is the product of all positive numbers less or equal to the number.
Factorial of number n is denoted by n! is calculated using the formula, n! = n*(n-1)*(n-2)*...*2*1.
To find the factorial of the entered number, we have used a for loop that runs from n to 1. At each iteration, i is multiplied with the factorial variable.
Example:
Input:
n = 5
Output:
factorial = 120 [5x4x3x2x1 = 120]
Program to find factorial of a number in Kotlin
Output
need an explanation for this answer? contact us directly to get an explanation for this answer