Programs - Sum of all numbers in Array
Write a program in c sharp to display sum of all the numbers in an array .
Demonstration of array
using system;
class Number
{
public static void Main()
{
int [] num = {10, 20, 30, 40, SO};
int n =. num.Length;
// Length is predefined attribute to access the size of array
console.write(" Elements of ,array are :");
for(int ;=0; i<n; i++)
{
console.writeLlne(num[i]);
}
int sum =0;
for(int i=O; i<n; i++) {
sum = sum +.num[i]); }
Console.writeLine(" The sum of elements :"+sum);
}
OUTPUT:
Elements of array are:
10
20
30
40
50
The sum of elements :150