How can I code a formula with power without using pow | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I code a formula with power without using pow

Using numbers that are positives (Example: 2^2 = 4; (-3)^2= 9) and negatives (Ex: 2^-2 = 0.25; (-3)^-2=) ands obtaining complete results (decimals if they have) and also calculate 0^0 (indeterminate). I will really apreciate it. Thanks ... EDIT: Please on an easy way. I mean I'm a begginer in c++ (university stuff)

27th May 2017, 12:53 AM
Cinty
Cinty - avatar
2 Answers
+ 1
Since exponentiation is repeated multiplication, use a loop to multiply a number by itself repeatedly. You'll probably need to check your inputs first to deal with error situations like 0^0 and throw an exception.
27th May 2017, 1:52 AM
Igor B
Igor B - avatar
0
Thanks Igor. The point is that I'm not as good at using loops as I'd like :'( ... but I'll definitely try :)
27th May 2017, 2:21 AM
Cinty
Cinty - avatar