I found an answer.
(define (fast-expt2 b n)
(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)))))
I'm a Japanese programmer. I write about C#, Ruby and JavaScript.
(define (fast-expt2 b n)
(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)))))
No comments:
Post a Comment