1.37|

$ cd ~

SICP Exercise 1.37

Recursive:

(define (cont-frac n d k)
  (cond ((= k 0) 0)
        (else (/ (n k) (+ (d k) (cont-frac n d (- k 1)))))))

Iterative:

(define (cont-frac n dk)
  (define (loop result term)
    (if (= term 0)
        result
        (loop (/ (n term)
                 (+ (d term) result))
              (- term 1))))
  (loop 0 k))