C Program Find Teranspose Matrix

/* C program to find Transpose of a Matrix www.easycodebook.com */ #include <stdio.h> int main() { int m, n, i, j, matrix1[10][10], transpose[10][10]; printf("Enter the number of rows and columns of the matrix[Maximum 10]:\n"); scanf("%d%d", &m, &n); printf("Please Enter %d elements Row wise in (%d rows x %d columns) matrix\n",m*n,m,n); printf("Please Remember, Each group of %d numbers will form a row of matrix\n",n); for (i = 0; i < m; i++) for (j = 0; j < n; j++) scanf("%d", &matrix1[i][j]); printf("The origional Matrix is:\n"); for (i = 0; i < m; i++) { for (j = 0 ; j < n; j++) printf("%d\t",matrix1[i][j]); printf("\n"); } /* producing Transpose matrix */ for (i = 0; i < m; i++) for (j = 0 ; j < n; j++) transpose[j][i] = matrix1[i][j]; printf("Transpose of the given Matrix is by swapping rows and columns:\n"); for (i = 0; i < n; i++) { for (j = 0 ; j < m; j++) printf("%d\t", transpose[i][j]); printf("\n"); } return 0; }

## Output

Enter the number of rows and columns of the matrix[Maximum 10]: 2 2 Please Enter 4 elements Row wise in (2 rows x 2 columns) matrix Please Remember, Each group of 2 numbers will form a row of matrix 1 2 3 4 The origional Matrix is: 1 2 3 4 Transpose of the given Matrix is by swapping rows and columns: 1 3 2 4 Another Sample Run / Output of the C Program Enter the number of rows and columns of the matrix[Maximum 10]: 2 3 Please Enter 6 elements Row wise in (2 rows x 3 columns) matrix Please Remember, Each group of 3 numbers will form a row of matrix 10 20 30 40 50 60 The origional Matrix is: 10 20 30 40 50 60 Transpose of the given Matrix is by swapping rows and columns: 10 40 20 50 30 60

## Definition of Transpose of a Matrix

The transpose of a matrix is a new matrix whose rows are the columns of the original.

### How Transpose of a Matrix is Obtained

To obtain transpose of a matrix we swap the rows and columns. Therefore, Transpose of a matrix is obtained by changing rows to columns and columns to rows. We can say that, transpose of a matrix A[][] is obtained by changing A[i][j] to A[j][i].

### Example matrix and its Transpose