Calculations

Calculate power of a number using recursion in C++

Calculate power of a number using recursion in C++

In this article, we will discuss the concept of Calculate power of a number  using recursion in C++ programming language

In this post, we will learn how to  find the power of a number using a recursive function in C language

Program 1

#include <iostream>
#include <conio.h>
using namespace std;

int find_Power(int num1,int num2);
int main()
{
    int base, powerValue, result;

    cout<<"Enter base number: ";
    cin>>base;

    cout<<"Enter power number: ";
    cin>>powerValue;

    result=find_Power(base,powerValue);

    cout<<base<<"^"<<powerValue<<" is "<<result;
    getch();
    return 0;
}

int find_Power(int base, int powerValue)
{
    if(powerValue !=0)
        return (base*find_Power(base,powerValue-1));
    else
        return 1;
}

When the above code is executed, it produces the following results

Enter base number: 3
Enter power number: 4
3^4 is 81

 

In the above program, the function find_Power() is a recursive function. When the power  is not equal to 0 the function recursively call it self to calculate power

When the power  is  equal to 0 the function return 1 – any number raised to the power of 0 is 1

you want to find power of any number, you can use pow() function in C++ language

 

Similar post

find the power of a number in C using recursion

find the power of a number in Python using recursion

 

Suggested for you

C++ recursion

C function

C user defined function

 

 

Recursion in Cpp programming language
Calculate sum of odd and even of an array in Java
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

6 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

6 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

6 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

9 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

1 year ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

1 year ago