📊⚡Beginner
Find the Transpose of Matrix
Transpose a matrix
Transpose of a matrix swaps rows and columns. If A is m×n, transpose is n×m.
Program Code
matrix_transpose.c
C
1#include <stdio.h>23int main() {4 int A[2][3] = {{1, 2, 3}, {4, 5, 6}};5 int T[3][2]; // Transpose dimensions swapped6 7 // Transpose8 for (int i = 0; i < 2; i++) {9 for (int j = 0; j < 3; j++) {10 T[j][i] = A[i][j];11 }12 }13 14 printf("Original Matrix (2x3):\n");15 for (int i = 0; i < 2; i++) {16 for (int j = 0; j < 3; j++)17 printf("%3d ", A[i][j]);18 printf("\n");19 }20 21 printf("\nTranspose (3x2):\n");22 for (int i = 0; i < 3; i++) {23 for (int j = 0; j < 2; j++)24 printf("%3d ", T[i][j]);25 printf("\n");26 }27 28 return 0;29}Output
Original Matrix (2x3):
1 2 3
4 5 6
Transpose (3x2):
1 4
2 5
3 6
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials