再帰で書くのは簡単。
(define (cont-frac n d k)
(define (recursive count)
(if (> count k)
0
(/ (n count) (+ (d count) (recursive (+ count 1))))))
(recursive 1))
反復で書くのも別に難しくは無いかな。(define (cont-frac n d k)
(define (iter product count)
(if (= count 0)
product
(iter (/ (n count) (+ (d count) product)) (- count 1))))
(iter 0 k))
再帰は上から、反復はしたから計算してく、と。
No comments:
Post a Comment