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

Programming Exercises

Write a function to calculate the power of a number using recursion.

Medium

Problem Statement

Write a function to calculate the power of a number using recursion.

Sample Input

A hardcoded base 2 and exponent 3

Sample Output

2 raised to the power of 3 is: 8

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
fun power(base: Int, exponent: Int): Int { // Add your recursive code here } fun main() { val base = 2 val exponent = 3 println("$base raised to the power of $exponent is: ${power(base, exponent)}") }
Log in or sign up to run or submit your code.Log inSign up
Input
A hardcoded base 2 and exponent 3
Expected Output
2 raised to the power of 3 is: 8