+ 2

How to calculate the sum of the values ​​of an array?

25th Mar 2017, 7:19 PM
Luis Armando Colón
3 Answers
+ 2
you can loop over all elements in the array and calculate the sum or you can simply call Sum() function on the array. for example int[] mArray={1,2,3}; Console.WriteLine(mArray.Sum()); // output: 6
25th Mar 2017, 8:52 PM
Mohamad Sharifi
Mohamad Sharifi - avatar
+ 1
print(sum([i for i in range(1,100)]}} will print the sum of a list from 1 to 100
25th Mar 2017, 7:46 PM
SAMI Awad
SAMI Awad - avatar
+ 1
int sum = 0; for (int i = 0; i < Array.Length(); i++) sum += Array[i] ; int sum = 0; foreach(int i in Array) sum += i; int sum = Array.Sum();
2nd Apr 2017, 10:02 PM
Yhal Htet Aung
Yhal Htet Aung - avatar