Write a function to calculate the power of a number iteratively.
HardProblem 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)}")
}
Input
Hardcoded values for base 2 and exponent 5.
Expected Output
2 raised to the power of 5 is: 32