Write a function to calculate the power of a number using recursion.
MediumProblem 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)}")
}
Input
A hardcoded base 2 and exponent 3
Expected Output
2 raised to the power of 3 is: 8