C# Program to find the sum of array elements


In this program, You will learn how to find the sum of array elements in C#.


int[] arr = new int[5];

Example: How to find the sum of array elements in C#.

using System;
public class Program
{
	public static void Main(string[] args)
	{
		int i, s = 0;
		int[] arr = new int[5];

		Console.Write("Enter five numbers:");

		for (i = 0; i < arr.Length; i++)
		{
			arr[i] = Convert.ToInt32(Console.ReadLine());
		}

		for (i = 0; i < arr.Length; i++)
		{
			s = s + arr[i];
		}
		Console.WriteLine("Sum is:" + s);
	}
}

Output:

Enter five numbers:10
20
30
40
50
Sum is:150