Pow(x, n)
MediumMath
Implement pow(x, n), which calculates x raised to the power n.
Example:
Input: x = 2, n = 10
Output: 1024
Input: x = 2, n = -2
Output: 0.25
Explanation: 2^(-2) = 1/2^2 = 1/4 = 0.25
Constraints:
- •
-100.0 < x < 100.0 - •
-2^31 <= n <= 2^31 - 1 - •
n is an integer - •
x is not zero when n is negative
Pow(x, n)
MediumMath
Implement pow(x, n), which calculates x raised to the power n.
Example:
Input: x = 2, n = 10
Output: 1024
Input: x = 2, n = -2
Output: 0.25
Explanation: 2^(-2) = 1/2^2 = 1/4 = 0.25
Constraints:
- •
-100.0 < x < 100.0 - •
-2^31 <= n <= 2^31 - 1 - •
n is an integer - •
x is not zero when n is negative
Press Run or Ctrl+Enter to execute