Write a C Program Program For Tranpose of matrix
#include<stdio.h>
#define ROW 3
#define COL 4
int main(void)
{
int mat1[ROW][COL], mat2[COL][ROW],i,j;
printf("Enter matrix mat1(%dx%d) row-wise : \n",ROW,COL);
for(i=0; i<ROW; i++)
for(j=0; j<COL; j++)
scanf("%d",&mat1[i][j]);
for(i=0; i<COL; i++)
for(j=0; j<ROW; j++)
mat2[i][j]=mat1[j][i];
printf("Transpose of matrix is:\n");
for(i=0; i<COL; i++)
{
for(j=0; j<ROW; j++)
printf("%5d",mat2[i][j]);
printf("\n");
}
return 0;
}
Output
Enter matrix mat1(3x4) row-wise :
36 38 40 42
44 46 48 50
52 54 56 58
Transpose of matrix is:
36 44 52
38 46 54
40 48 56
42 50 58