0

Not understanding array in calculation

I did not understand ( Array in ca Calculation ) lesson. It is not clear to me . Can anyone help?

16th Nov 2018, 7:10 AM
Mohanad Methkal
1 Answer
+ 2
It is just another example how to use arrays. While the other examples set or changed individual "compartments" of the array, the calculation example uses a variable "sum" as accumulator to reduce an array of numbers to its total sum. int arr[] = {11, 35, 62, 555, 989}; int sum = 0; for (int x = 0; x < 5; x++) { sum += arr[x]; } cout << sum << endl; Such scenarioes may well arise. For instance: sample data. Read them into an array and later work with the array to calculate some statistical information [like mean value, median, deviation and the like]. Then you need to perform operations over an entire array of variable size of values.
16th Nov 2018, 7:22 AM
Leif
Leif - avatar