Two Dimensional Array in C

Two dimensional array in C programming is represented in the form of rows and columns, also known as a matrix. It is also known as array of arrays or list of arrays.

Printing Elements of Two Dimensional Array

Program

#include<stdio.h>
#include<conio.h>
void main()
{      //'stud' is name of Two Dimensional Array and assigning
int stud[4][2] = {{1234, 56}, //elements to it.
                  {1212, 33},
                  {1434, 80},
                  {1312, 78}};
for(int row = 0; row < 4; row++) //loop looping on Rows.
{
for(int col = 0; col < 2; col++) //loop looping on Columns.
{
printf("%d  ", stud[row][col]); //and printing Rows and Columns.
}
printf("\n");
}
getch();
}
//U can also Declare Array like
 //'int stud[4][2] = {1234, 56, 1212, 33, 1434, 80, 1312, 78};' And
 //'int stud[][2] = {1234, 56, 1212, 33, 1434, 80, 1312, 78};' And
/* 'int stud[4][2];
    stud[0][0] = 1234;
    stud[0][1] = 56;
    stud[1][0] = 1212;
    stud[1][1] = 33;
    stud[2][0] = 1434;
    stud[2][1] = 80;
    stud[3][0] = 1312;
    stud[3][1] = 78;' */
Output
1234  56
1212  33
1434  80
1312  78

Program User Enter Values in Two Dimensional Array Printing

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int stud[4][2]; //this is array which have 4 Rows and 2 Columns.
for(int row = 0; row < 4; row++)
{
for(int col = 0; col < 2; col++)
{
printf("Enter value for stud[%d][%d]: ", row, col);
scanf("%d", &stud[row][col]); //user Enter value storing in 'stud' Array.
}
}
printf("The Output of Array is:\n");
for(int r = 0; r < 4; r++)
{
for(int c = 0; c < 2; c++)
{
printf("%d   ", stud[r][c]); //printing Elements of 'stud' Array.
}
printf("\n");
}
getch();
}
Output
Enter value for stud[0][0]: 22
Enter value for stud[0][1]: 65
Enter value for stud[1][0]: 38
Enter value for stud[1][1]: 76
Enter value for stud[2][0]: 39
Enter value for stud[2][1]: 11
Enter value for stud[3][0]: 19
Enter value for stud[3][1]: 70
The Output of Array is:
22   65
38   76
39   11
19   70