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 in a project named something like 03_PCE_StudentCode.  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 Program.cs file, in the same project) to informally test this yourself (remember to set this project as the Startup Project in order to run this program).

 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.