+ 5

int arr[] = {11, 35, 62, 555, 989}; int sum = 0; for (int x = 0; x < 5; x++) { sum += arr[x]; } cout << sum << endl

guys can anyone help to solve this .... what is the output and how it works

27th Nov 2016, 4:31 PM
Bhairesh M
Bhairesh M - avatar
8 odpowiedzi
+ 24
Our array consists of 5 elements. We use the for loop to count the indices of the array. x starts from 0 and goes to 4, as we start to count the indices of the array from 0. We have an integer sum which is 0 at the beginning and then we add all the values of each element of our array to the sum. So after all we will get the sum of all elements which is 1652 (if I am not mistaken).
27th Nov 2016, 4:48 PM
Rebeka Asryan
Rebeka Asryan - avatar
+ 3
The Output is a error message that endl needs a semicolon haha :D I'm jokeing :) , Output is 1652 :) the for loop adds all numbers together and the Output is the sum of all numbers
27th Nov 2016, 4:40 PM
Max_N
Max_N - avatar
+ 2
output:11+35+62+555+989=1652
29th Nov 2016, 1:09 PM
Ali Kamyanfar
Ali Kamyanfar - avatar
+ 1
11+35+65+555+989=1652 sum+=arr[x] is same as sum=sum+arr[x] where the value of x in the array makes it possible to select each number from the array.
31st Jul 2018, 3:12 PM
igoni Obebharo Talbot
igoni Obebharo Talbot - avatar
0
thanks guys...
27th Nov 2016, 4:56 PM
Bhairesh M
Bhairesh M - avatar
0
here just adding all the elements of array will give you answer that is 1652
27th Nov 2016, 6:08 PM
Dhruv Saxena
Dhruv Saxena - avatar
0
hahaha
16th Jan 2017, 10:03 AM
just play
just play - avatar
0
1652
5th Feb 2017, 6:31 PM
Utkarsh Aggarwal
Utkarsh Aggarwal - avatar