C++ Program for Power Function using Recursion
Example: Input: N=5;x=3;
Output: 125
#include <iostream>
using namespace std;
int Power(int N,int k)
{
if(k==0)
{
return 1;
}else
if(k==1)
{
return N;
}else
{
return N*Power(N,k-1);
}
}
int main()
{
int N,x;
cout<<"Enter the base"<<endl;
cin>>N;
cout<<"Enter the Power"<<endl;
cin>>x;
cout<<N<<"^"<<x<<" = "<<Power(N,x);
return 0;
}
Comments
Post a Comment