C/C++ Arena

Step 6 of 6

2D arrays

A 2D array is an array of rows:

int grid[2][3] = {
    {1, 2, 3},
    {4, 5, 6},
};
printf("%d\n", grid[1][2]);   // row 1, column 2: 6

Loop over it with nested loops: rows outside, columns inside.

Your turn: read a 3x3 grid of numbers and print the sum of each row on its own line, then the sum of the main diagonal (top-left to bottom-right) as diag N.

Previous: Modify an array in a function