Write a Kotlin function to calculate the factorial of a number.
EasyProblem Statement
Write a Kotlin function to calculate the factorial of a number.
Sample Input
A hardcoded integer, e.g., 5.
Sample Output
The factorial of 5 is: 120
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
fun factorial(n: Int): Int { // Add your code here to calculate the factorial } fun main() { val number = 5 println("The factorial of $number is: ${factorial(number)}") }
Input
A hardcoded integer, e.g., 5.
Expected Output
The factorial of 5 is: 120