C Program to find Transpose of Matrix

This page has a C Program to C Program to find Transpose of Matrix. It is clear that, this C program will display the Transpose of Matrix. The Rows of the given matrix is changed into Columns in the Transpose of Matrix and the columns of the given matrix is changed into rows in the Transpose of Matrix. For Example: If we give elements for 2 by 2 matrix, the 1st row of the matrix will be changed into 1st Column of the Transpose of Matrix and the 2nd row of the matrix will be changed into 2nd Column of the Transpose of Matrix. The below given C program will Print Transpose of Matrix. Kindly check out the program to display the Transpose of Matrix.

Transpose of Matrix Program

#include<stdio.h>

int main() {

int M[20][20];

int m, n, i, j;

printf("

Enter the Row and Column sizes of Matrix : ");

scanf("%d %d", &m, &n);

printf("



Enter the Matrix elements one by one

");

for (i = 1; i<=m; i++)

for (j = 1; j<=n; j++)

scanf("%d", &M[i][j]);

printf("

The Given Matrix is :



");

for (i = 1; i<=m; i++){

for (j = 1; j<=n; j++)

printf(" %d ", M[i][j]);

printf("



");

}

printf("

The Transpose of the given Matrix is :



");

for (i = 1; i<=n; i++){

for (j = 1; j<=m; j++)

printf("\t %d", M[j][i]);

printf("



");

}

return(0);

} Sample Output:

Enter the Row and Column sizes of Matrix : 2 4



Enter the Matrix elements one by one

0

1

2

3

4

5

6

7

8



The Given Matrix is :



0 1 2 3



4 5 6 7



The Transpose of the given Matrix is :



0 4



1 5



2 6



3 7

Related Popular Posts: