Recursive sum method
public class SumPrices { public static double Sum(double[] p, int start, int end) { if (start < end) return p[start] + Sum(p,start+1,end); else return 0; } public static void Main() { double[] prices = {1.3, 13.68, 314.919, 82.827, 363.949}; System.Console.WriteLine("The sum is {0:C}", Sum(prices,0,prices.Length)); } }
1. | Use a recursive method, travel, to journey from start to finish | ||
2. | Recursive Factorial method. | ||
3. | Recursive function in action | ||
4. | Define function | ||
5. | Catch StackOverflowException for recursive function |