find the sum of a two-dimensional array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

find the sum of a two-dimensional array

27th Nov 2017, 7:21 PM
Vitos
3 Answers
+ 2
You can browse the table using two nested loops
27th Nov 2017, 7:40 PM
Elegis Sossou
Elegis Sossou - avatar
+ 2
Yes, just like this, considering an array arr[4][5] for(int i=0; i<4; i++) for(int j=0; j<5; j++) sum+=arr[i][j]
27th Nov 2017, 7:45 PM
Elegis Sossou
Elegis Sossou - avatar
0
What @Elegis said, you can nest two for loops. The first loop will loop through each array in the array, and the second loop will loop through each element in that array.
27th Nov 2017, 7:42 PM
Zeke Williams
Zeke Williams - avatar