Back to course home
0% completed
Vote For New Content
19. Pow(x,n)
Problem Statement
Write a Recursive Approach to Calculate Power of Integer to N Pow(x,n).
Given an integer x
and an integer n
, write a recursive function to calculate the power of x
to the n
th power.
Example
Sr# | x | n | Output | Description |
---|---|---|---|---|
1 | 2 | 5 | 32 | 2 raised to the power of 5 equals 32. |
2 | 3 | 4 | 81 | 3 raised to the power of 4 equals 81. |
3 | 5 | 0 | 1 | Any number raised to the power of 0 equals 1 (x^0 = 1). |
Constraints:
-100.0 < x < 100.0
- -2<sup>31</sup> <= n <= 2<sup>31</sup>-1
n
is an integer.- Either
x
is not zero or n > 0. - -10<sup>4</sup> <= x<sup>n</sup> <= 10<sup>4</sup>
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Example
Try it yourself