# Review Questions

1:

What is the output from the following method if you call it with the argument 1?

` 01: public static void Recurs(int number) 02: { 03:     if(number > 8) 04:         return; 05:     else 06:     { 07:         Console.WriteLine("Number: { 0} ", number); 08:         Recurs(number * 2); 09:     } 10: } `
2:

Identify in the Recurs method of question 1 the main ingredients found in most successful recursive methods.

3:

Rewrite the Recurs method in question 1 so that it (by still using recursion) provides the following output if called with the argument 16.

` Number: 16 Number: 8 Number: 4 Number: 2 Number: 1 `
4:

Which technique provides for the most efficient solution recursion or iteration? Why?

5:

The following Sum method is supposed to calculate the sum of a series of numbers starting at the argument passed to Sum and decrementing until 1 is reached. For example, Sum of 4 is supposed to be 4 + 3 + 2 + 1 = 10, and Sum of 1 is 1. However, Sum has a couple of missing parts. Make the corrections.

` public static int Sum(int number) {     return number + Sum(number 1); } `
6:

Consider the ruler in Figure 23.4. Describe the fundamental logic behind a recursive method that can draw this ruler.

##### Figure 23.4. A recursive ruler.

C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

Similar book on Amazon