The problem. Implement pow(x, n), which calculates x raised to the power n (xⁿ). n is an integer that may be negative, as small as −2³¹.
x = 2.0, n = 10 -> 1024.0
x = 2.1, n = 3 -> 9.261
x = 2.0, n = -2 -> 0.25 (1 / 2^2)Members only · free account
The rest of this lesson, with 7 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson