;to calculate (expt b n) call (fast-expt-iter 1 b n)
(define (fast-expt-iter a b n)
(cond ((= n 0) a)
((even? n)
(fast-expt-iter a (square b) (/ n 2)))
(else (fast-expt-iter (* a b) b (- n 1)))))
(define (even? n)
(= (remainder n 2) 0))
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment