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

Leave Comment

Important Topics

Title
Terminologies in C Sharp
Introduction to C Sharp
Hello World Program
C vs C Sharp
C Sharp vs C Plus Plus
C SHARP vs JAVA
Array and Types of Array
Programs - Sum of all numbers in Array
Strings and Types of Strings
Delegates in C sharp
System Collection Generic
System.Collections Classes
System.Collections.Concurrent
Dot Net Assembly
Events in C Sharp