Example 38: Calculate Power

Learn how to calculate n raised to power m.

Problem

Write a function that receives two numbers, n and exponent, and calculates the value of n raised to the given exponent.

Example

Input (n^ exponent) Output
2^ -5 0.031250
2^ 0 1.000000
2^ 5 32.000000
3.2^ 4 104.857605

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Get hands-on with 1400+ tech skills courses.