HomeC++C++ program to Calculate the Power using Recursion

# C++ program to Calculate the Power using Recursion

In this post, you will learn how to Calculate the Power using Recursion in C++.

This lesson will teach you how to Reverse a Sentence Using Recursion, mathematical operators and decision making statement using the C++ Language. Letâ€™s look at the below source code.

## Source Code

```#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,power;
cin>>base>>power;
cout<<base<<" raised to the power "<<power<<" is "<<FindPower(base, power);
return 0;
}```

`3 5`

## Output

`3 raised to the power 5 is 243`

The statementsÂ #include<iostream>, using namespace std, int mainÂ are the main factors that support the function of the source code.

Now we can look into the working and layout of the codeâ€™s function.

1. Declare theÂ variables FindPower, base, powerÂ asÂ integers.Â Declare theÂ if statementÂ with the condition `(power == 0)` andÂ returnÂ the value 1.
2. In theÂ else statementÂ return the mathematical expression `base * FindPower(base, power-1)` .
3. Starting with int mainÂ declare the variables base,powerÂ asÂ integers.
4. Using theÂ cinÂ and theÂ coutÂ statement collect the base and the power from the user and display the answer. The base, the power and the calculated answer is displayed.

### You May Also Like

#### C++ Program to Generate Multiplication Table

In this post, you will learn how to Generate Multiplication Table using C++ programming language. This lesson will teach you...
• C++
• January 30, 2022

#### C++ Program to Display Fibonacci Sequence

In this post, you will learn how to Display Fibonacci Sequence using C++ programming language. This lesson will teach you...
• C++
• January 30, 2022

#### C++ Program to Find GCD of two Numbers

In this post, you will learn how to Find GCD of two Numbers using C++ programming language. This lesson will...
• C++
• January 30, 2022