Secondary diagonal in 2D array | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Secondary diagonal in 2D array

how to find the summation of the variables in the secondary diagonal of an array with c++ program?

30th Mar 2017, 3:06 AM
Huda Zaher
Huda Zaher - avatar
4 Answers
+ 8
What's a secondary diagonal?
30th Mar 2017, 3:30 AM
Karl T.
Karl T. - avatar
+ 8
So if you have an array like this: 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 The secondary diagonal would be 0,2 1,1 2,0 ?
30th Mar 2017, 3:46 AM
Karl T.
Karl T. - avatar
+ 8
If that's the case I would use a nested for loop and check if that for index (i,j) if((i+j)== (n-1)) where n is the number of rows/columns in the array (assuming that it is square). If that is true then add array[i][j] to a variable sum.
30th Mar 2017, 3:56 AM
Karl T.
Karl T. - avatar
0
google it 😒
30th Mar 2017, 3:38 AM
Huda Zaher
Huda Zaher - avatar