Grokking the Art of Recursion for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
19. Pow(x,n)
On this page

Problem Statement

Example

Try it yourself

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 nth power.

Example

Sr#xnOutputDescription
125322 raised to the power of 5 equals 32.
234813 raised to the power of 4 equals 81.
3501Any 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