2D Array Cl8
2D Array Cl8
2D Array Cl8
-------------------------------------
Double Dimensional
------------------
To store more than one value of similar type in a single variable using different
rows and columns
int n[3][3]={{1,2,3},{4,5,6},{7,8,9}};
1 2 3
[0,0] [0,1] [0,2]
4 5 6
[1,0] [1,1] [1,2]
7 8 9
[2,0] [2,1] [2,2]
printf("\n%d",n[2][3]); error
printf("\n%d",n[2][1]); 8
printf("\n%d",n[1][2]); 6
--------------------------------------
int n[3][2]={{1,2},{3,4},{5,6}};
1 2
[0,0] [0,1]
3 4
[1,0] [1,1]
5 6
[2,0] [2,1]
printf("\n%d",n[0][0]); 1
printf("\n%d",n[2][1]); 6
printf("\n%d",n[1][0]); 3
int n[3][3]={1,2,3,4,5,6,7,8,9};
int n[3][3]={1,2,3,4,5,6};
--------------------------------------
1 2 3
4 5 6
7 8 9
printf("\n%d",n[0][1]+n[1][2]); 8
printf("\n%d",n[1][2]-n[2][2]); -3
printf("\n%d",n[0][0]*n[2][1]); 8
printf("\n%d",n[2][1]/n[1][0]); 2
------------------------------------------
void main()
{
int n[3][3]={{1,2,3},{4,5,6},{7,8,9}};
int i,j;
for(i=0;i<3;i++) loop to trace row
{
for(j=0;j<3;j++) loop to trace column
{
printf("%d\t",n[i][j]);
}
printf("\n");
}
}
i=0
j=0 to 2
i=1
j=0 to 2
i=2
j=0 to 2