// This program prints out a 2D array // Remember that a 2D array is initialised with size: // array[row][col] - this means that col is the inner loop, whilst row // are the outer loop // Sasha Vassar Week 4, Lecture 7 #include // Problem: Print out a 2D array of numbers. Declare the 2D array and initialise // it with numbers // 1. Declare a 2D array // 2. Initialise the array with random values // 3. Print out the array as a grid (i.e. a 2D array) #define N_ROWS 3 #define N_COLS 4 int main(void) { // int array[3]= {1, 2, 3} int array[N_ROWS][N_COLS] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; int row = 0; while (row < N_ROWS) { int col = 0; while (col < N_COLS) { printf("%d ", array[row][col]); col++; } printf("\n"); row++; } return 0; }