L.F.16.1

lab exercise

 

fibonacci

 

 

 

Background:

 

             The Fibonacci number series is defined as follows:

 

Position             0           1           2           3           4           5           6           7           8           etc.

 

Fib number        0           1           1           2           3           5           8           13         21         etc.

 

Positions 0 & 1 are definition values.  For positions greater than 1, the corresponding Fibonacci value of position N = Fib (N-1) + Fib (N-2).

 

 

 

Assignment:

 

1.    Write a recursive function that takes in a single integer (X >= 0) and returns the appropriate Fibonacci number of the Fibonacci number series.

 

2.    Write a non-recursive Fibonacci function which solves the same problem as the recursive version.

 

3.    Write a function which solves a multiplication problem recursively.  Use this function prototype:

 

       int  mult  (int a,  int b)

       //  solves for (a * b) by recursively adding a, b times.

       //  precondition:  0 <= a <= 10;  0 <= b <= 10.

 

 

 

 

Instructions:

 

Use these sample run output values:

 

Recursive fibonacci:  fib (0), fib (3), fib (11)

 

Non-recursive Fibonacci:  nonRecFib (1), nonRecFib (5), nonRecFib (14)

 

Recursive multiplication:  mult (0,4), mult (3,1), mult (7,8), mult (5,0)