# SICP Goodness - Continued Fraction

SICP Exercise 1.37

Do you think Computer Science

equalsbuilding websites and mobile apps?Are you feeling that you are doing

repetitiveandnot so intelligentwork?Are you feeling a bit

sickaboutreading manualsandcopy-pastingcode and keeppoking arounduntil it worksall day long?Do you want to understand the

soulofComputer Science?If yes,

read SICP!!!

Writing recursive functions is not an easy task, often requires a different way of thinking.

For practice purpose, let’s now take a look at an exercise from the book.

# Recursive Process

```
(define (cont-frac-iter n d k i)
(if (= k i)
(/ (n k) (d k))
(/ (n i) (+ (d i) (cont-frac-iter n d k (+ i 1))))))
(define (cont-frac n d k)
(cont-frac-iter n d k 1))
```

# Iterative Process

```
(define (cont-frac-iter n d k r)
(if (= k 1)
r
(cont-frac-iter n d (- k 1) (/ (n (- k 1)) (+ (d (- k 1)) r)))))
(define (cont-frac n d k)
(cont-frac-iter n d k (/ (n k) (d k))))
```

# Tips

The two types of recursive procedure can be illustrated below.

## Share this post

Twitter

Google+

Facebook

Reddit

LinkedIn

StumbleUpon

Email