Introduction to Programming in C# – Exercise 1

In this exercise, you will modify this program:

In its current form, the program produces the Fibonacci number for n=8:

Fibonacci number for n = 8: 21

Modify line 39 to produce other Fibonacci numbers.

In this exercise, your task is to modify the methods public List getFibonacciSeries(int n) and public static void Main() such that the program produces the following output for n=8:

Fibonacci sequence for n = 8: [1, 1, 2, 3, 5, 8, 13, 21]

Before you modify the program, make sure that you understand its code. Specifically:

  • What does each method do?
  • What are the required input parameters, and what are their types?
  • What value does the method return, and what is its type?
  • What are the steps in which each method creates a result that is returned?

The method public List<int> getFibonacciSeries(int n) currently does not perform relevant data processing. It simply returns an empty list of integers. You will modify this method as part of this exercise.

Steps to complete the exercise:

  1. Read and understand the program’s code (see above).
  2. Create an account on .NET Fiddle.
  3. Open the program in your .NET Fiddle account.
  4. Create a new version of the original program by choosing ‘Fork’ in the .NET Fiddle menu.
  5. Modify the program. ‘Save’ frequently in order not to lose work.
  6. Submit:
    1. Copy a link to your fiddle using ‘Share’ > ‘Share Link’.
    2. Submit the link on TUWEL until Monday, October 16, 5pm.

Grading criteria:

  • Correctness of the Fibonacci sequence.
  • Correct formatting of the Fibonacci sequence (values separated by with opening and closing brackets [ and ]): [1, 1, 2, 3, 5, 8, 13, 21].
  • Tidy code formatting (this is similar to a professionally drawn floor plan):
    • Use indentation (see code examples).
    • Consistent formatting.
    • Add comments where necessary. This helps you and others understand your code.

Extra credits:

  • The computation of Fibonacci sequences is not very efficient. Modify your program accordingly and submit it as a separate Fiddle.