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
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
Comments
Leave a comment