Two Dimensional Arrays: General Form of An 2D Array Is Datatype Array - Name (Row - Size) (Column - Size)
Two Dimensional Arrays: General Form of An 2D Array Is Datatype Array - Name (Row - Size) (Column - Size)
Two Dimensional Arrays: General Form of An 2D Array Is Datatype Array - Name (Row - Size) (Column - Size)
Ex:
int
array_ name[row_size][column_size];
i[4][3];
c1
c2
c3
r1
r2
r3
r4
10
11
12
4X3
MEMORY OF 2 D ARRAY:
In memory it is not possible to store elements in form of rows and
columns. Whether it is a 1 D (or) 2 D Array, the elements are stored in
continuous memory locations. The arrangement of elements of a 2 D is
shown below:
int a[4][3] = = { { 10,20,30 } , { 4,8,9 } , { 23,41,32 } , { 15,18,24 } };
a[0][0] a[0][1] a[0][2]
a[1][0]
a[1][1] a[1][2]
..a[3][2]
10
20
30
4
1000 1002 1004
8
9
1006
23
41
1008
1022
// WAP to read a 2-D Array and print it.
Void main()
{
int a[10][10] , i , j , m , n ;
Clrscr();
32
15
.
18
24
//
for rows.
//
for columns.
//
for rows.
//
for columns.
{
for (j=0;j<n;j++)
{
Scanf(%d, &a[i][j]);
}
}
for(i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
printf(%d, a[i][j]);
}
Print( \n );
}
}
}
printf("\n");
}
getch();
}
if(c1 == r2)
{
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c2;k++)
{
c[i][j] =c[i][j] + (a[i][k] * b[k][j]);
}
}
}
printf("\nProduct of the two matrices is\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf(" %d",c[i][j]);
}
printf("\n");
}
}
else
printf("Matrix multiplication not possible");
getch();
}
scanf("%d",&a[i][j]);
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
b[j][i] = a[i][j];
}
}
printf("Transpose of given matrix is\n");
for(i=0;i<c1;i++)
{
for(j=0;j<r1;j++)
{
printf("%d ",b[i][j]);
}
printf("\n");
}
if(r1 == c1)
{
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
if(i==j)
a[i][j] = 1;
else
a[i][j] = 0;
}
}
}
printf("\n");
}
}
else
printf("\nIdentity matrix should be square matrix");
getch();
}
{
printf("enter elements of the matrix-1\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
printf("\n");
}
}
/*printing matrix-1*/
printf("matrix-1\n\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n\n\n");
}
/* printing matrix-2*/
printf("matrix-2\n\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%d\t",b[i][j]);
printf("\n\n\n");
}
/* checking equality */
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
if(a[i][j]!=b[i][j])
{
temp=1;
break;
}
}
}
}
else
printf("cannot be compared");
if(temp==1)
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
printf("\n");
}
}
printf("the input matrix is\n\n\n\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n\n\n\n\n\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=a[j][i];
}
}
}
printf("\n\n\n\n\n\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(a[i][j]!=b[i][j])
{
temp=0;
//printf("matrix is symmetric");
}
}
}
if(temp==0)