int base;
int exp;
int answer = 1
for(int i = 0; i<n; i++)
{answer*=base}
This code above works, I just don't understand the functionality. "answer*=base" doesn't seem to have anything to do with "i" or "exp". I don't understand the logic behind it all.
Excuse me, I wrote the code wrong. n is supposed to be the exp.
So it goes:
int base;
int exp;
int answer = 1;
for(int i=0; i<exp; i++)
{answer*=base;}
This format works, and when output the exponent of any base is printed.
I just don't understand {ans*+base;}
... how does this simple statement work? It leaves out both i and exp.??
answer *= base is the same thing as answer = answer * base. i and exp doesn't have to be used in the actual calculation. It's just there to make sure base is multiplied the correct number of times. 2 to the power of 3 is 8. 2 is the base, 3 is the exp. But to calculate it, it's 2 * 2 * 2. There's no need to actually use exp in the calculation.