+ 2
How to calculate the sum of the values of an array?
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
+ 1
print(sum([i for i in range(1,100)]}}
will print the sum of a list from 1 to 100
+ 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();