Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Pow(x, n)

XPChallenge Points: 20
levelLevel: Medium

Implement a function that returns the exponential value of a number, computed as x to the power n.
Handle cases where n is zero, positive, or negative.
Precision of floating-point arithmetic should be maintained up to at least 5 decimal places.

Example 1:

Input: x = 10.00000, n = 2

Output: 100.00000

Example 2:

Input: x = 0.50000, n = 4

Output: 0.06250

Explanation:

0.5⁴ = 0.5 × 0.5 × 0.5 × 0.5 = 0.0625

Example 3:

Input: x = 3.00000, n = -2

Output: 0.11111

Explanation:

3⁻² = 1/9 ≈ 0.11111

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result