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

Programming Exercises

Write a function to calculate the power of a number iteratively.

Hard

Problem Statement

Write a function to calculate the power of a number iteratively.

Sample Input

Hardcoded values for base 2 and exponent 5.

Sample Output

2 raised to the power of 5 is: 32

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
fun calculatePower(base: Int, exponent: Int): Int { // Add your code here to calculate the power } fun main() { val base = 2 val exponent = 5 println("$base raised to the power of $exponent is: ${calculatePower(base, exponent)}") }
Log in or sign up to run or submit your code.Log inSign up
Input
Hardcoded values for base 2 and exponent 5.
Expected Output
2 raised to the power of 5 is: 32