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 ... |
Get C# Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.