In this tutorial, I am going to discuss how to calculate power using recursion.
Problem statement – Write a code to implement function pow(x, n), which calculates x raised to the power n (i.e. x^n). In this problem, We don’t have to use in-built function Math.pow.
For example:
Example 1:
Input: x = 2.00000, n = 3
Output: 8
Example 2:
Input: x = 2.10000, n = 3
Output: 9.26100
Example 3:
Input: x = 2.00000, n = -2
Output: 0.25000