Transpose a Matrix in C
Here, you will get and learn the example code of Transpose a Matrix in C language.
Transpose is the process of exchanging the values of rows and columns of a matrix.
Transpose a Matrix in c program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | //Transpose of a matrix in c #include <stdio.h> #define ROW 2 #define COL 3 int main() { int mat[ROW][COL], transpose[COL][ROW]; int i, j; printf("Enter the elements of matrix:\n"); for (i = 0; i < ROW; i++) for (j = 0; j < COL; j++) scanf("%d", &mat[i][j]); printf("\nEntered Matrix:\n"); for (i = 0; i < ROW; i++) { for (j = 0; j < COL; j++) printf("%d\t", mat[i][j]); printf("\n"); } for (i = 0; i < ROW; i++) for (j = 0; j < COL; j++) transpose[j][i] = mat[i][j]; printf("\nMatrix after Transpose :\n"); for (i = 0; i < COL; i++) { for (j = 0; j < ROW; j++) printf("%d\t", transpose[i][j]); printf("\n"); } return 0; } |
Output
Check out our other C programming Examples