Develop and write a procedure make-^ which inputs a single parameter n and which returns a procedure
raiseToNthPower. The procedure raiseToNthPower must itself input a single parameter b, and must
return b^n. You may assume that n is an integer.
please, use scheme language
Solution:
Screenshot of the code:
Sample Output:
Code To Copy:
;Function to be used in raiseToNthPower().
(define (myabs x)
(cond ((< x 0) (* x -1))
((x >= 0) (* x 1))))
;Define the function to compute x ^ y.
(define (raiseToNthPower x y)
;Condition to check the value of x.
(cond ((< x 0) (* (cond ((odd? (myabs y)) -1)
(else 1))
(raiseToNthPower (myabs x) y)))
((< y 0) (/ 1 (raiseToNthPower x (myabs y))))
((= y 0) 1)
((> y 0) (* x (raiseToNthPower x (- y 1))))))
;Call the function by passing the values.
(raiseToNthPower 2 3)
Get Answers For Free
Most questions answered within 1 hours.