Scheme Exercises

back to exercise list       previous     next

Group:     Exercise: 2/48 

Fibonacci:  The famous sequence

Create a function called "fib" which, given a single positive
integer argument "n", will return the "nth" number in the
Fibonacci sequence. The Fibonacci sequence starts with a pair of ones, conventionally numbered as term 1 and term 2. Each succeeding term is the sum of the previous two:

    1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,...
So, to start off with: (fib 1) => 1 and (fib 2) => 1
and (fib 3) => 2 and (fib 10) => 55