Mid/SeniorMathRecursion

Pow(x, n)

Implement pow(x, n), which calculates x raised to the power n, that is x^n.

Example 1
Inputx = 2, n = 10
Output1024
2 raised to the 10th power equals 1024.
Example 2
Inputx = 2, n = -2
Output0.25
2 raised to the -2nd power equals 1 divided by 2 squared, which is 0.25.

Constraints

  • -100.0 < x < 100.0
  • -2^31 <= n <= 2^31 - 1
  • n is an integer
  • Either x != 0 or n > 0
  • -10^4 <= x^n <= 10^4

Asked at 22 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate