Transpose A Matrix
Transpose A Matrix
EXAMPLE PROGRAM 1
#include <stdio.h>
int main()
{
int m, n, i, j, a[10][10], transpose[10][10];
printf("Enter the number of rows and columns of a matrix\n");
scanf("%d%d", &m, &n);
printf("Enter elements of the matrix\n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{ OUTPUT :
scanf("%d", &a[i][j]); Enter the number of rows and
} columns of a matrix
}
for (i = 0; i < m; i++) 3
{ 3
for (j = 0; j < n; j++) Enter elements of the matrix
{ 123
transpose[j][i] = a[i][j]; 456
} 789
Transpose of the matrix:
}
147
printf("Transpose of the matrix:\n"); 258
for (i = 0; i < n; i++) 369
{
for (j = 0; j < m; j++)
{
printf("%d\t", transpose[i][j]);
}
printf("\n");
}
return 0;
}
TRANSPOSE OF A MATRIX
EXAMPLE PROGRAM 2
#include <stdio.h>
int main()
{
int m, n,i,j, a[10][10];
printf("Enter the number of rows and columns of a matrix\n");
scanf("%d%d", &m, &n);
printf("Enter elements of the matrix\n");
for (i = 0; i < m; i++)
{ OUTPUT:
for (j = 0; j < n; j++) Enter the number of rows and columns of a matrix
{ 3
scanf("%d", &a[i][j]); 3
} Enter elements of the matrix
123
}
456
printf("The matrix is\n"); 789
for (i = 0; i < m; i++) The matrix is
{ 123
for (j = 0; j < n; j++) 456
789
{
Transpose of the matrix:
printf("%d\t", a[i][j]);
1 2 3
} 4 5 6
printf("\n"); 7 8 9
}
printf("\n Transpose of the matrix:\n");
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++)
{
printf("%d\t", a[i][j]);
}
printf("\n");
}
return 0;
}