Recursive sum method : Function Definition : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Function Definition »

 

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));
  }
} 

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Function Definition