SICP 练习1.8 求立方根

只需要将1.7的程序的improve改成题目中给的式子即可

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

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

(define (good-enough? guess x)
  (< (/ (abs (- guess x)) guess) 0.00001))

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

(define (cube x)
  (cube-iter 1.0 x))

(cube 27)
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/NMfloat/article/details/51550483
个人分类: SICP
上一篇SICP 练习1.7
下一篇SICP 练习1.9
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭