Answer to Question #258488 in Algorithms for JONIE

Question #258488

Let b is a real number. Let n be a non -negative integer. Assume b and n are not

simultaneously 0. Write iterative and recursive functions that return value of b n, the nth power of b


1
Expert's answer
2021-10-29T03:59:01-0400

Iterative function:

function poweri(b, n)
Let res = 1
For i from 1 to n do
    let res = res * b
Next i
Return res



Recursive function:

function powerr(b, n)
If n equal 0 
    Return 1
Let res = power(b, n-1)
Return res * b

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS