datatype arrayname [m][n];
Here,
arrayname
is the name of a two-dimensional array that contains the elements of the
datatype
mentioned and has ‘m’ number of rows and ‘n’ number of columns.
For example,
int a[10][20];
It declares that ‘a’ is a two-dimensional array with dimensions of (10 * 20).
How to Access 2d Arrays in C
An individual data item of a 2D array is accessed by specifying the row and column of a 2d array as
follows:
a[i] [j];
where ‘i’ refers to the row number and ‘j’ refers to the column number.
For example, a[1][2]
refers to the data item in the 2nd row and 3rd column (noting that indexing
in C starts from 0).
How to Read Elements into a 2d Array in C
We read in the values of 2d arrays by using two nested for loops as follows:
for(i=0; i
{
for(j=0;j
scanf(“%d”, &num[i][j]);
}
Do'stlaringiz bilan baham: