SICP习题 1.12 (帕斯卡三角的递归与迭代)

(define (pascal row col)
(cond ((or (< col 0) (< row 0))
(display"behave yourself!"))
((> col row)
(display"behave yourself!"))
((or (= col 0) (= col row))
1)
(else (+ (pascal (- row 1) (- col 1))
(pascal (- row 1) col)))))

(pascal 4 -3)

 

 

(define (factorial n)
(fact-iter 1 1 n))

(define (fact-iter a i n)
(if (> i n)
a
(fact-iter (* a i)
(+ i 1)
n)))
;(factorial 3)
(define (pascal row col)
(/ (factorial row)
(* (factorial col)
(factorial (- row col)))))

(pascal 1024 256)

 

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

你可能感兴趣的:(SICP习题 1.12 (帕斯卡三角的递归与迭代))