Recursively Printing Even Numbers

 

The goal for this exercise is to start writing recursive code.  You’ll start here, with a task that resembles previous code samples that you’ve seen, but that is different enough that you (hopefully) will have to give the task some thought.

 

For this exercise, you need to implement the PrintEvenNumbers_Iteratively method in the provided RecursiveMethods class. 

 This class should be found in the Student_Answers.cs file.  This class will print out only even numbers, from N down to 0 (including zero), using a perfectly normal loop.   The objective here is to code up the problem in a simple, straight-forward way that will allow you visually see what work is being done at each step of the program. 

You may want to use the Recursively_Printing_Even_Numbers.RunExercise method (in the Student_Answers.cs file) to informally test this yourself.

 Once you’ve done that, implement the PrintEvenNumbers_Recursively method in your RecursiveMethods class.  This should print out only even numbers, from N down to 0 (including zero), but this time will do so recursively

What you need to do for this exercise: 

  1. Implement the PrintEvenNumbers_Iteratively method to print even numbers using a loop
    1. Test this out on your own, using the Program.cs file.
    2. The format of the output must match what the NUnit test is expecting EXACTLY.  Here's an example of 'correct' output, when told to print values starting with 5 (notice that 5 is not even)
      Argument: 4
      Argument: 2
      Argument: 0
      1. You'll need to match the spelling, capitalization, and spacing exactly (there's 1 space between the "Argument:" and the number).  Anything else will cause the test to fail.
  2. Implement the PrintEvenNumbers_Recursively method that will print even numbers recursively.
  3. Once you’ve completed the above task, you should run the tests in the NUnit_Tests_PrintEven_Recursive 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.