trace what happens in this function in Lisp please when base

trace what happens in this function in Lisp please when base=3 and exp=2. It\'s recursive.

Trace what happens in this function in Lisp please when base=3 and exp=2. It\'s recursive. (defun power (base exp) (if (eq exp 0) 1 (*base (power base (-exp 1)))) > (power 3 2) 9

Solution

This function will return the power of the number. Basicall the first number base ^ exponent given in the function.

we are recursively multiplying the number in the function call and subtracting the exponent value by1 once each call is made to the function. In case the exponent becomes one we make it 1.

so power 3 2 will return 3^2 = 9

so 9 will be returned.

trace what happens in this function in Lisp please when base=3 and exp=2. It\'s recursive. Trace what happens in this function in Lisp please when base=3 and ex

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site