## C Program To Find Transpose of Matrix

Learn How To Find Transpose of Matrix in C Programming Language. It is important that we should know **How A For Loop Works** before getting further with this transpose program.

#### What is a Matrix?

A Matrix is basically an Array Data Structure consisting of Multiple Rows and Columns. It is also known as a Three – Dimensional Matrix.

#### How To Calculate Transpose of Matrix?

To find the Transpose of any Matrix, you need to **Interchange Rows with Columns of Matrix** and **Columns with Rows** of the Matrix.

The Transpose of any Matrix can be found out by different methods. The first method focuses on a simple implementation that copies the Rows of First Matrix into the Columns of Second Matrix and the Columns of First Matrix into the Rows of Second Matrix. The Second method makes use of a Single Matrix Array where the Rows are converted into columns and columns are converted into Rows. The Third method makes use of Functional approach in C Programming

**Also Read: Find Sum of Diagonal Elements of Matrix C Program**

#### Method 1: C Program To Print Transpose of Matrix without using Functions

#include<stdio.h> int main() { int arr1[3][3], arr2[3][3], i, j; printf("\nEnter Elements for 3 * 3 Matrix:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { scanf("%d", &arr1[i][j]); } } printf("\nElements of Matrix are:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { printf("%d\t", arr1[i][j]); } printf("\n"); } for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { arr2[i][j] = arr1[j][i]; } } printf("\nTranspose of Matrix:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { printf("%d\t", arr2[i][j]); } printf("\n"); } printf("\n"); return 0; }

**Must Read: C Program To Sort 1 – Dimensional Array in Ascending Order**

#### Method 2: C Program To Find Transpose of Matrix using One Array

#include<stdio.h> int main() { int arr1[3][3], i, j, temp; printf("\nEnter Elements for 3 * 3 Matrix:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { scanf("%d", &arr1[i][j]); } } printf("\nElements of Matrix are:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { printf("%d\t", arr1[i][j]); } printf("\n"); } for(i = 0; i < 3; i++) { for(j = 0; j < i; j++) { temp = arr1[i][j]; arr1[i][j] = arr1[j][i]; arr1[j][i] = temp; } } printf("\nTranspose of Matrix:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { printf("%d\t", arr1[i][j]); } printf("\n"); } return 0; }

**Must Read: C Program For Multiplication of Two Matrices**

#### Method 3: C Program To Calculate Transpose of Matrix using Function

#include<stdio.h> int transpose(int arr1[3][3]) { int arr2[3][3], i, j; for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { arr2[i][j] = arr1[j][i]; } } printf("\nTranspose of Matrix:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { printf("%d\t", arr2[i][j]); } printf("\n"); } return 0; } int main() { int i = 3, j = 3; int arr1[i][j]; printf("\nEnter Elements for 3 * 3 Matrix:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { scanf("%d", &arr1[i][j]); } } printf("\nElements of Matrix are:\n"); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { printf("%d\t", arr1[i][j]); } printf("\n"); } transpose(arr1); printf("\n"); return 0; }

**Must Read: C Program To Calculate Sum of Lower Triangle Elements**

#### Output

In case you get any Compilation Errors or have any doubts in this code to Find Transpose of a Matrix in C Programming, let us know about it in the Comment Section below.

Fantastic. This is just awesome. I was finding transpose using only one array variable and I got so many variants.

Transpose Program is so simple. I had thought it was very difficult. I could not make the for loop. Tried so many variants. This code is good.

I finally understood how to pass array to a function with the help of this C program to find transpose of a matrix. Thanks.