Task 8 of 9 · 0 solved · 9 to go0%
You can read the problem, but answers are checked only for signed-in students. Sign in to answer →

5.4 2D arrays — diagonal total

Total: 0 / 3 pts
Practice mode — check each part and get hints as you go.
Task

Fill in diagonalSum so that it returns the sum of the main diagonal — the elements where the row number equals the column number.

For the 3×3 grid the diagonal is 1, 5, 9, so the program prints 15. One loop is enough, not two.

Your solution