Jun 8, 2015 at 7:57am UTC
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!
Jun 8, 2015 at 8:26am UTC
Repeated multiplication using a for-loop or similar would be a good start. At least for integer exponentiation.
Jun 8, 2015 at 1:33pm UTC
You can create a function like: int potency(int const& a,int const& b); And try while or for loop
Jun 8, 2015 at 2:16pm UTC
int const &
-->int
There's no need for a const reference to an integer type. OP's prototype is sufficient.
Jun 8, 2015 at 2:34pm UTC
For non integer calculations you can use series expansion or logarithms ( series expansion here also ).
Jun 8, 2015 at 2:38pm UTC
(OP's problem is a common introductory course homework.)