Home C Language Basic C Programs Transpose Of Matrix in C

Transpose Of Matrix in C

In linear algebra, the transpose of a matrix is an operator which flips a matrix over its diagonal; that is, it switches the row and column indices of the matrix A by producing another matrix, often denoted by AT, as follows:

Write a program in C to find transpose of a given matrix.

#include<stdio.h>

int main()

{

int m,n,i,j;

int a;

printf(“Enter size of matrix:\n”);

scanf(“%d%d”,&m,&n);

printf(“Enter elements into matrix:\n”);

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

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

scanf(“%d”,&a[i][j]);

printf(“Given matrix is:\n”);

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

{

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

printf(“%d\t”,a[i][j]);

printf(“\n”);

}

printf(“Transpose of given matrix is:\n”);

for(i=0;i<n;i++)

{

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

printf(“%d\t”,a[j][i]);

printf(“\n”);

}

return 0;

}

Output:

Enter size of matrix:

4              2

Enter elements into matrix:

14           18           12           36           84           62           23           25

Given matrix is:

14           18

12           36

84           62

23           25

Transpose of given matrix is:

14           12           84           23

18           36           62           25