Two Dimensional Array in C
Here you will get simple 2d array program in c language. In which, you will learn that how to declare two dimensional array, input values in array, and print the values of array.
Example of 2d Array Program in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<stdio.h> int main() { int i, j, num[3][3]; //Input elements in array printf("\nEnter elements in 2d array :"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&num[i][j]); } } //Print 2D array for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("arr[%d] [%d] = %d \n",i,j,num[i][j]); } } return 0; } |
Output
Enter elements in 2d array :3
2
5
4
7
11
8
77
34
2
5
4
7
11
8
77
34
arr[0] [0] = 3
arr[0] [1] = 2
arr[0] [2] = 5
arr[1] [0] = 4
arr[1] [1] = 7
arr[1] [2] = 11
arr[2] [0] = 8
arr[2] [1] = 77
arr[2] [2] = 34
arr[0] [1] = 2
arr[0] [2] = 5
arr[1] [0] = 4
arr[1] [1] = 7
arr[1] [2] = 11
arr[2] [0] = 8
arr[2] [1] = 77
arr[2] [2] = 34