I need to find A raise to the power b, simply power ( a, b ) without the use of multiplication and division operator
Ex: pow ( 2, 3 ) = 8
I am unable to understand the intuition behind this code.
int pow(int a, int b)
{
if (b == 0)
return 1;
int answer = a;
int increment = a;
int i, j;
for(i = 1; i < b; i++)
{
for(j = 1; j < a; j++)
{
answer += increment;
}
increment = answer;
}
return answer;
}