Fibonacci Numbers (And Arrays!)

advertisement
Arrays & Recursion
The goal for this exercise is to practice writing (increasingly complex) recursive
code, this time using a modern twist on a classic example of recursion.
For this exercise, you need to implement the Fibonacci_Array method in
the provided RecursiveMethods class.
This class should be found in the Student_Answers.cs file in a project named
something like 03_PCE_StudentCode. Fibonacci_Array will fill an array with
the Fibonacci numbers, recursively. The array to be filled will be passed in as a
parameter. Remember that the Fibonacci numbers are defined as follows:
Fibonacci(0) = 0
Fibonacci(1) = 1
Fibonacci(N) = Fibonacci(N – 1) + Fibonacci(N – 2)
Once you’ve done this, make sure that all the tests in the
class pass.
NUnit_Tests_Fibonacci_Array
Hint: You may want to start this by implementing the method using a loop.
Once you've got that up and running, replace the loop with a recursive function to
print out the array.
What you need to do for this exercise:
1. Implement Fibonacci_Array, as described above
2. Once you’ve completed the above task, you should run the tests in the
NUnit_Tests_Fibonacci_Array class. They should all pass at this point, and if
not, then you should fix your program so that those tests do pass. You can
run the tests using the NUnit support in the provided starter project. You
should feel free to supplement that code with your own test cases if you wish,
but you are neither required nor expected to.
Download