码迷,mamicode.com
首页 > 其他好文 > 详细

SICP的一些练习题

时间:2014-10-15 20:50:11      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   ar   sp   div   art   

1.3 较大两个数之和

bubuko.com,布布扣
1 (define (MaxSum x y z)
2   (+ (cond ((or (> x y) (> x z)) x)
3            (else 0))
4      (cond ((or (> y x) (> y z)) y)
5            (else 0))
6      (cond ((or (> z x) (> z y)) z)
7            (else 0))))
8 (MaxSum 5 3 10)
较大两个数之和

牛顿迭代

bubuko.com,布布扣
 1 (define (Abs x)
 2   (cond ((> x 0) x)
 3         ((= x 0) 0)
 4         ((< x 0) (- x))))
 5 (define (Square x) (* x x))
 6 (define (Average x y)
 7   (/ (+ x y) 2))
 8 (define (Improve guess x)
 9   (Average guess (/ x guess)))
10 (define (GoodEnough? guess x)
11   (< (Abs (- (Square guess) x)) 0.001))
12 (define (SqrtIter guess x)
13   (if (GoodEnough? guess x)
14       guess
15       (SqrtIter (Improve guess x)
16                 x)))
17 (SqrtIter 1 2)
牛顿迭代

 

SICP的一些练习题

标签:style   blog   http   color   os   ar   sp   div   art   

原文地址:http://www.cnblogs.com/zinthos/p/4027009.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!