#include<stdio.h>
int main()
{
int i,j,p,q,a[10][10],c[10][10];
printf("\nEnter the number of rows and columns of the matrix \n\n");
scanf("%d%d",&p,&q);
printf("\nEnter the %d elements of the matrix \n\n", p*q);
for(i = 0; i< p; i++)
{
for(j = 0; j< q; j++)
{
scanf("%d", &a[i][j]);
}
}
for(i = 0; i< p; i++)
{
for(j = 0; j< q; j++)
{
c[i][j]=a[j][i];
}
}
printf("\n\nThe Transpose of matrix is: \n\n");
for(i = 0; i < p; i++)
{
for(j= 0; j< q; j++)
{
printf("%d\t", c[i][j]);
}
printf("\n");
}
return 0;
}
Note: Need to be arranged in compiler after copied
OutPut:
Enter the number of rows and columns of the matrix
3
3
Enter the 9 elements of the matrix
1
4
7
2
5
8
3
6
9
The Transpose of matrix is:
1 2 3
4 5 6
7 8 9