C# - Find sum of numbers in an array.


C# - Find sum of numbers in an array.

CODE
using System; class Program { public static void Main() { int[] numbers = { 1, 2, 3, 4, 5 }; int sum = 0; //loop through the numbers and calculate the sum for(int i = 0; i < numbers.Length; i++) { sum += numbers[i]; } Console.WriteLine("Sum = {0}", sum); //OUTPUT //Sum = 15 Console.ReadKey(); } }

Comments