sicp-answer~> 1-8

按照题目提示写一遍即可, 把之前的 sqrt 换成 curt, 修改下 improve 函数即可:
(sqrt: square root, 平方根)
(curt: cube root, 立方根)

(define (curt x)
  (curt-iter 1.0 x))

(define (curt-iter guess x)
  (if (good-enough? guess (improve guess x))
    (improve guess x)
    (curt-iter (improve guess x) x)))

(define (square x)
  (* x x))

(define (improve guess x)
    (/ (+ (/ x (square guess)) (* 2 guess))
       3))

(define (good-enough? old-guess guess)
  (> 0.01
    (/ (abs (- guess old-guess))
        old-guess)))

上一篇: 1-7
下一篇: 1-9

柳下川
如果你发现文章有错误, 麻烦联系我, 当然单纯想加个QQ好友找我聊天也行, 欢迎你耶! :)
(这算是一种扩列吗? 嘿嘿)
--> 2948804617
--> jedsek@qq.com
--> Jedsek
--> B站个人主页
--> 知乎个人主页