Matrix:
-Multidimensional Array
-Matrix consist of the rows and columns.
Syntax-
array[row][column]
//Martix with numbers of rows and columns
Transpose of matrix:
Example-
matrix is:
1 2 3
4 5 6
Transpose is:
1 4
2 5
3 6
program-
#include< stdio.h>
int main()
{
int a[10][10],b[10][10],r,c,i,j;
printf("Enter rows and columns for Matrix\n");
scanf("%d%d",&r,&c);
//input in matrix
printf("Enter %d number in matrix\n",r*c);
for(i=0;i< r;i++)
{
for(j=0;j< c;j++){
scanf("%d",&a[i][j]);
}
}
//Matrix
printf("Your matrix isn");
for(i=0;i< r;i++)
{
for(j=0;j< c;j++)
{
printf("%d ",a[i][j]);
}
printf("n");
}
//Transpose of the matrix
printf("Transpose of the matrix\n");
for(i=0;i< r;i++)
{
for(j=0;j< c;j++)
{
printf("%d ",a[j][i]);
}
printf("\n");
}
}
Enter rows and columns for Matrix
3 3
Enter 9 number in array
1 2 3 4 5 6 7 8 9
Your matrix is
1 2 3
4 5 6
7 8 9
Transpose of the matrix
1 4 7
2 5 8
3 6 9