# C Program to Find Transpose of given Matrix

A matrix which is formed by exchanging the values of all the rows of a given matrix into columns and vice-versa. The transpose of matrix A is written A^{T}.

Program executes in simple steps as

Read Matrix elements

Display Matrix elements

Display Transpose of Matrix by interchanging rows and columns.

// C program to accept a matrix of order MxN and find its transpose #include <stdio.h> #define ROWS 3 #define COLS 3 void main() { int mat[ROWS][COLS]; int i, j; printf("Enter the elements of the matrix\n"); for (i = 0; i < ROWS; ++i) { for (j = 0; j < COLS; ++j) { scanf("%d", &mat[i][j]); } } printf("The given matrix is \n"); for (i = 0; i < ROWS; ++i) { for (j = 0; j < COLS; ++j) { printf(" %d", mat[i][j]); } printf("\n"); } printf("Transpose of matrix is \n"); for (i = 0; i < ROWS; ++i) { for (j = 0; j < COLS; ++j) { printf(" %d", mat[j][i]); } printf("\n"); } }

Download Code : matrix-transpose.c (56 downloads)

###### Output