print 2d array in c

To print a 2D array in C, you can use nested loops to iterate over the rows and columns of the array. Here is an example code snippet:

#include <stdio.h>

#define ROWS 3
#define COLS 4

int main() {
    int arr[ROWS][COLS] = {{1, 2, 3, 4},
                           {5, 6, 7, 8},
                           {9, 10, 11, 12}};

    for (int i = 0; i < ROWS; i++) {
        for (int j = 0; j < COLS; j++) {
            printf("%d ", arr[i][j]);
        }
        printf("\n");
    }

    return 0;
}

This code declares a 2D array arr with dimensions ROWS and COLS, and initializes it with some values. The nested for loops iterate over each element of the array and use printf to print the values. The outer loop iterates over the rows, and the inner loop iterates over the columns. After printing each row, a newline character (\n) is printed to move to the next line.

When you run this code, it will output:

1 2 3 4
5 6 7 8
9 10 11 12

This is the 2D array printed row by row.