Two Dimension Array in C Program
A two-dimensional (2D) array is a multi-dimensional data structure that stores data in rows and columns, similar to a table or matrix.This is a simple C program that demonstrates how to work with a 2D array and iterate through its elements to print them.
Example : print_2darray.c
#include <stdio.h> int main() { int rows = 3, cols = 3; int array[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; printf("2D Array Elements:\n"); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { printf("%d ", array[i][j]); } printf("\n"); } return 0; }
Output:
2D Array Elements:
1 2 3
4 5 6
7 8 9
1 2 3
4 5 6
7 8 9