Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a Kotlin function to calculate the factorial of a number.

Easy

Problem 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)}") }
Log in or sign up to run or submit your code.Log inSign up
Input
A hardcoded integer, e.g., 5.
Expected Output
The factorial of 5 is: 120