power of number

107

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

Comments

Submit
0 Comments