3) if n> 3. Write a procedure that computes f by means of a recursive process. Write a procedure that
computes f by means of an iterative process.
iterative:
16(define (f n)
17 (define (f-iter product1 product2 product3 counter)
18 (if (= 0 counter)
19 product3
20 (f-iter (+ product1 (* 2 product2) (* 3 product3))
21 product1
22 product2
23 (- counter 1))))
24 (f-iter 2 1 0 n))
recuisive:
77(define (f n)
78 (cond ((= n 0) 0)
79 ((= n 1) 1)
80 ((= n 2) 2)
81 (else (+ (* 1 (f (- n 1)))
82 (* 2 (f (- n 2)))
83 (* 3 (f (- n 3)))))))
Exercise 1.12. The following pattern of numbers is called Pascal's triangle.
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.
95(define (pascal x y)
96 (cond ((= x 1) 1)
97 ((= x y) 1)
98 (else (+ (pascal (- x 1) (- y 1))
99 (pascal x (- y 1))))))
x ,y start from 1 respectively.