SICP习题 1.18 (对求乘积进行优化)

mac2022-06-30  26

(define (double a) (+ a a)) (define (halve a) (/ a 2)) (define (mult a b) (mult-iter a b 0)) (define (mult-iter a b product) (cond ((= b 0) product) ((even? b) (mult-iter (double a) (halve b) product)) ((odd? b) (mult-iter a (- b 1) (+ a product))))) (mult 123 124)

  

转载于:https://www.cnblogs.com/R4mble/p/7889849.html

相关资源:SICP 习题答案
最新回复(0)