Power Using Recursion

PHOTO EMBED

Sun Feb 06 2022 23:13:54 GMT+0000 (Coordinated Universal Time)

Saved by @Uttam #java #gfg #geeksforgeeks #recursion #powerusing recursion #power

class Solution
{
    static int RecursivePower(int n, int p)
    {
       if(p==0){
           return 1;
       }
       return n*RecursivePower(n, p-1);
    }
}
content_copyCOPY

Power Using Recursion You are given two numbers n and p. You need to find n^p. Example 1: Input: n = 9 p = 9 Output: 387420489 Explanation: 387420489 is the value obtained when 9 is raised to the power of 9. Example 2: Input: n = 2 p = 9 Output: 512 Explanation: 512 is the value obtained when 2 is raised to the power of 9. Your Task: You don't need to read input or print anything. You only need to complete the function RecursivePower() that takes n and p as parameters and returns n^p. Expected Time Complexity: O(p). Expected Auxiliary Space: O(p). Constraints: 1 <= n <= 9 0 <= p <= 9

https://practice.geeksforgeeks.org/problems/power-using-recursion/1/?track=DSASP-Recursion&batchId=190