标签:style blog http color os ar sp div art
1.3 较大两个数之和
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)
牛顿迭代
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)
标签:style blog http color os ar sp div art
原文地址:http://www.cnblogs.com/zinthos/p/4027009.html