Solution to SICP Exercise 1.16

Structure and Interpretation of Computer Programs

Solution to Exercise 1.16:

(define (even? n)
(= (remainder n 2) 0))

(define (square x)
(* x x))

(define (it-fast-expt b n)
(iter 1 b n))

(define (iter a b n)
(cond ((= n 0) a)
((even? n) (iter a (square b) (/ n 2)))
(else (iter (* a b) b (- n 1)))))

One thought on “Solution to SICP Exercise 1.16”

Comments are closed.

%d bloggers like this: