+ 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)

2 Antworten

+ 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.

0

Thanks Igor. The point is that I'm not as good at using loops as I'd like :'( ... but I'll definitely try :)