- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

The power of a number can be calculated as x^y where x is the number and y is its power.

For example.

Let’s say, x = 2 and y = 10 x^y =1024 Here, x^y is 2^10

A program to find the power using recursion is as follows.

#include <iostream> using namespace std; int FindPower(int base, int power) { if (power == 0) return 1; else return (base * FindPower(base, power-1)); } int main() { int base = 3, power = 5; cout<<base<<" raised to the power "<<power<<" is "<<FindPower(base, power); return 0; }

3 raised to the power 5 is 243

In the above program, the function findPower() is a recursive function. If the power is zero, then the function returns 1 because any number raised to power 0 is 1. If the power is not 0, then the function recursively calls itself. This is demonstrated using the following code snippet.

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

In the main() function, the findPower() function is called initially and the power of a number is displayed.

This can be seen in the below code snippet.

3 raised to the power 5 is 243

- Related Questions & Answers
- How to calculate Power of a number using recursion in C#?
- Java program to calculate the power of a Given number using recursion
- Write a C# program to calculate a factorial using recursion
- C++ program to Calculate Factorial of a Number Using Recursion
- How to calculate fractional power using C#?
- C++ Program to Calculate Power of a Number
- How to calculate power of three using C#?
- C program to calculate power of a given number
- How to calculate the power exponent value using C#?
- Find power of a number using recursion in C#
- Java program to calculate the GCD of a given number using recursion
- C++ Program to Find G.C.D Using Recursion
- Write a program to Calculate Size of a tree - Recursion in C++
- Raise x to the power n using Recursion in Java
- Java program to calculate the power of a number

Advertisements