Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 47: Write a C++ program to calculate the power of a number using recursion.

#include<iostream>
using namespace std;

int power(int base,int num)
{
	if(num==1)
		return base;
	else
		return base*power(base,num-1);
}

int main()
{
	int base,num;
	cout<<"\nenter the base and power : ";
	cin>>base>>num;
	cout<<"\nresult : "<<power(base,num);
	return 0;
}


If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.