Search
 
SCRIPT & CODE EXAMPLE
 

CPP

recursive power in c++

#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;
}
Comment

power in c++ using recursion

#include <iostream>
using namespace std;

int power (int a , int n );
int main()
{
    cout << " Please enter number = " ;
    int a , n ;
    cin >> a ;
    cout << " Please enter power = " ;
    cin >> n ;
    cout << " Answer is = " << power ( a , n );
    return 0;
}

int power (int a , int n )
{
    if ( n != 0)
        return a * power ( a  , n -1 );
    else
        return 1;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ file to string 
Cpp :: c++ absolute value 
Cpp :: qlabel set text color 
Cpp :: recursive binary search 
Cpp :: how to print text on C++ 
Cpp :: input a string in c++ 
Cpp :: convert vector into array c++ 
Cpp :: vector of int to string c++ 
Cpp :: how to open and print in a file in c++ 
Cpp :: retu7rn this c++ 
Cpp :: cpp take lambda as parameter 
Cpp :: c++ show current time 
Cpp :: what is __asm in C++ 
Cpp :: how to get command arguments c++ 
Cpp :: convert int to string c++ 
Cpp :: how to check is some number is divisible by 3 in c++ 
Cpp :: c++ array loop 
Cpp :: how to compare lower case character to uppercase cpp 
Cpp :: maximum int c++ 
Cpp :: chrono library c++ 
Cpp :: c++ typedef 
Cpp :: Rick Astley - Never Gonna Give You Up 
Cpp :: c++ char it is a number 
Cpp :: cpp binary tree 
Cpp :: find primes in cpp 
Cpp :: memcpy library cpp 
Cpp :: set was not declared in this scope 
Cpp :: divide and conquer based algorithm to find maximum and minimum of an array 
Cpp :: sort index c++ 
Cpp :: ue4 float to fstring 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =