mediumRecursion
Pow(x, n)
## Problem
Implement `pow(x, n)`, which calculates `x` raised to the power `n` (i.e., `x^n`).
Implement `pow(x, n)`, which calculates `x` raised to the power `n` (i.e., `x^n`).
Examples
Input
x = 2.0, n = 10
Output
1024.0
2^10 = 1024.
Input
x = 2.1, n = 3
Output
9.261
2.1^3 = 9.261.
Input
x = 2.0, n = -2
Output
0.25
2^-2 = 1/4 = 0.25.
Constraints
-100.0 < x < 100.0
-2^31 <= n <= 2^31 - 1
n is an integer.
Either x is not zero or n > 0.
-10^4 <= x^n <= 10^4
Python
Loading...