sicp 1.38

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

(define (cont k)
  (let ((value (cont-frac (lambda (x) 1)
                          d
                          k)))
    (display value)
    (newline)
    (if (> k 10)
        k
        (cont (+ k 1)))))

(define (d i)
  (if (= (remainder i 3) 2)
      (* 2.0 (+ 1 (quotient i 3)))
      1.0))

(cont 1)

 

1.0
0.6666666666666666
0.75
0.7142857142857143
0.71875
0.717948717948718
0.7183098591549296
0.7182795698924731
0.7182835820895522
0.7182817182817183
0.7182818352059925
11

你可能感兴趣的:(SICP)