C++ Program to Calculate Power using Recursion

Write C++ Program to Calculate Power using Recursion

// CPP Program to Calculate Power using Recursion

#include <iostream>

using namespace std;

int Power(int base, int n)
{
	if(n != 0)
		return base * Power(base,n-1);
	else
		return 1;
}
int main()
{
	int base, n;
	cout << "Enter Base Number :--> ";
	cin >> base;

	cout << "Enter Power:--> ";
	cin >> n;

	int result = Power(base,n);

	cout << base << "^" << n << " = " << result;

	return 0;
}

Output:

Enter Base Number :--> 5
Enter Power:--> 6
5^6 = 15625

≪ Previous | Next ≫