Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

power of a number

#include <iostream>
using namespace std;

long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}

int main()
{
    long long x = 5;
    long long y = 16;
    
    cout << "Power is " << binpow(x, y);
    return 0;
}
Source by cp-algorithms.com #
 
PREVIOUS NEXT
Tagged: #power #number
ADD COMMENT
Topic
Name
5+5 =