Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
}
 
PREVIOUS NEXT
Tagged: #power #recursion
ADD COMMENT
Topic
Name
5+9 =