Example 38: Calculate Power

Learn how to calculate n raised to power m.


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


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.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.