pow without math h

Solutions on MaxInterview for pow without math h by the best coders in the world

showing results for - "pow without math h"
Marlene
20 May 2020
1int pow(int base, int exp)
2    {
3      if(exp < 0)
4        return -1;
5
6        int result = 1;
7        while (exp)
8        {
9            if (exp & 1)
10                result *= base;
11            exp >>= 1;
12            base *= base;
13        }
14
15        return result;
16    }
17