Recursion to compute (a power b)

please tell if this approach is correct ???
int power(int a, int b)
{
if(b==1)
{
return a;
}
int ans=a*power(a,b-1);
return ans;
}

@gunjan13082000 Yes…your approach is correct. But instead you should have a base case as
if(b==0)
return a;

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.