2D Array in C
Level 4149 keystrokes
Creates a 2D array and prints all elements using nested loops.
C code
// 2 rows x 3 columns: each inner {} initializes one row1int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}};// Outer loop walks the rows (i = 0, 1)2for (int i = 0; i < 2; i++) { // Inner loop walks the columns of row i (j = 0, 1, 2)3 for (int j = 0; j < 3; j++) { // matrix[row][column] reads one element; print it followed by a space4 printf("%d ", matrix[i][j]);5 } // End the row with a newline: "1 2 3 " then "4 5 6 "6 printf("\n");7}Output
1 2 3 4 5 6
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
;× 7,× 6{× 5}× 5"× 4(× 4)× 4[× 4]× 4+× 4