Find Transpose of Matrix
Code:
#include <stdio.h>
#include <conio.h>
int main()
{
int a[10][10],b[10][10];
int i, j, row, col;
printf("enter the no of rows and cols");
scanf ("%d%d", &row, &col);
printf("enter elements of matrix");
for (i=0; i<row; ++i)
for (j=0; j<col; ++j)
scanf ("%d", &a[i][j]);
// find the transpose
for (i=0; i<row; ++i)
for (j=0; j<col; ++j)
b[j][i]=a[i][j];
//print the transpose
for (i=0; i<row; ++i)
{ for (j=0; j<col; ++j)
printf ("%d\t", b[i][j]);
printf ("\n");
}
getch();
return 0;
}
Output:
enter the no of rows and cols3
3
enter elements of matrix4
5
56
8
7
9
45
5
1
4 8 45
5 7 5
56 9 1
--------------------------------
Process exited after 15.11 seconds with return value 0
Press any key to continue . . .