Making my own pow

Hi,i wanna make(or see) a "homemade" pow code.
int potency(int base , int exponent) that shall calculate potencys.
So like: potency(2, 3) shall give the result 8.(2^3=2*2*2=8)
would be very thankful for help!


closed account (48T7M4Gy)
Repeated multiplication using a for-loop or similar would be a good start. At least for integer exponentiation.
You can create a function like: int potency(int const& a,int const& b); And try while or for loop
int const&-->int
There's no need for a const reference to an integer type. OP's prototype is sufficient.
closed account (48T7M4Gy)
For non integer calculations you can use series expansion or logarithms ( series expansion here also ).
(OP's problem is a common introductory course homework.)
Topic archived. No new replies allowed.