but the function is changed:
f(n) = n if n < 3 2*f(n-1)+f(n-2)-f(n-3) otherwise
(define (recursive x)
(cond ((= x 0) 0)
((= x 1) 1)
((= x 2) 2)
(else (- (+ (* (recursive (- x 1)) 2) (recursive (- x 2)))
(recursive (- x 3))))
)
)
(define (interative x)
(cond ((= x 0) 0)
((= x 1) 1)
((= x 2) 2)
(else (do-interative 0 1 2 (- x 2)))
)
)
(define (do-interative a b c x)
(cond ((= x 0) c)
(else (do-interative b c (- (+ (* c 2) b) a) (- x 1)))
)
)
XDXDXD老師寄信到我信箱說:
回覆刪除interative-> iterative
XDXD 我真的耍蠢了XDXD