Here's a C Program to find the transpose of a given matrix with proper explanation and output. This program uses Multidimensional Arrays, Nested Loops and For Loops.

Note:The transpose of a matrixAis another matrixA^{T}created by any one of the following equivalent actions:

- reflect
Aover its main diagonal (which runs top-left to bottom-right) to obtainA^{T}- write the rows of
Aas the columns ofA^{T}- write the columns of
Aas the rows ofA^{T}

# include <stdio.h> # include <conio.h> void main() { int mat[10][10] ; int i, j, row, col ; clrscr() ; printf("Enter the order of the matrix : ") ; scanf("%d %d", &row, &col) ; printf("\nEnter the elements of the matrix : \n\n") ; for(i = 0 ; i < row ; i++) for(j = 0 ; j < col ; j++) scanf("%d", &mat[i][j]) ; printf("\nThe transpose matrix is : \n\n") ; for(i = 0 ; i < col ; i++) { for(j = 0 ; j < row ; j++) { printf("%d \t", mat[j][i]) ; } printf("\n") ; } getch() ; }

**Output of the above program**

Enter the order of the matrix : 2 3

Enter the elements of the matrix :

1 2 3

4 5 6

The transpose matrix is :

1 4

2 5

3 6

**Explanation of above program**

In this program, we have a square matrix

*mat*of maximum size 10 x 10. The variables i and j are the loop variables that corresponds to the row and column of the matrix respectively.
Next, the program prompts the user to enter order of the matrix. Notice the syntax of first

**scanf**. It is used to take two space separated numbers as input. The first number will be stored in*row*variable and the second number will be stored in*col.*
Next, using the first Nested For Loop the program populates the matrix

*mat*and using the second nested for loop the program finds out the transpose of the matrix. The transpose is calculated by replacing the rows and columns of the given matrix.