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.??
User Profile
Collapse
Profile Sidebar
Collapse
amandastanko
Last Activity: Apr 10 '12, 04:17 PM
Joined: Feb 5 '12
Location:
-
How do I raise any number x to a positive power n using a for loop?
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*=ba se" doesn't seem to have anything to do with "i" or "exp". I don't understand the logic behind it all.
No activity results to display
Show More
Leave a comment: