Horje
Program To Calculate Number Power Using Recursion In C++. The power number should always be positive integer. Code Example
Program To Calculate Number Power Using Recursion In C++. The power number should always be positive integer.
#include <iostream>
using namespace std;

int calculatePower(int, int);

int main()
{
    int base, powerRaised, result;

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

    cout << "Enter power number(positive integer): ";
    cin >> powerRaised;

    result = calculatePower(base, powerRaised);
    cout << base << "^" << powerRaised << " = " << result;

    return 0;
}

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




Cpp

Related
split the array there is an array val of n integers . A good subarray is defined as Code Example split the array there is an array val of n integers . A good subarray is defined as Code Example
c for loop decrement Code Example c for loop decrement Code Example
c++ program to convert  kelvin to fahrenheit Code Example c++ program to convert kelvin to fahrenheit Code Example
c++ cstring to string Code Example c++ cstring to string Code Example
how to print std::string Code Example how to print std::string Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10