The numbers at the edge of the triangle are all 1, and each number inside the triangle is the sum of the two numbers above it.35 Write a procedure that computes elements of Pascal's triangle by means of a recursive process.
#lang scheme
(define (pascal_triangle a b )
(cond
((= a b) 1)
((= a 2) 1)
((= b 1) 1)
(else (+ (pascal_triangle (- a 1) (- b 2))
(pascal_triangle (- a 1) (- b 1))))))
--------------------------------------------------------------------------------
;;; sicp 1.12
#lang scheme
(define (pascal_triangle a b )
(cond
((< a b) '틀렸음)
((= a b) 1)
((= b 1) 1)
(else (+ (pascal_triangle (- a 1) (- b 1))
(pascal_triangle (- a 1) b)))))
수정함
댓글 없음:
댓글 쓰기