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.
#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;' */
#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();
}