# Transpose of a Matrix in C

Hello and Welcome to The World of Computer Science and Technology

www.TechWithCode.com

Today we will learn about how to write a C Program to find the Transpose of a Matrix in C. Before moving forward, we must have knowledge about what Transpose of a Matrix is?

What is the Transpose of a Matrix?

The transpose of a matrix is simply a flipped version of the original matrix. We can transpose a matrix by switching its rows with its columns. For example, consider the following 3 X 2 matrix:

1 2

3 4

5 6

Transpose of the matrix:

1 3 5

2 4 6

When we transpose a matrix, its order changes, but for a square matrix, it remains the same.

## Transpose of a Matrix in C:

#### Problem Statement⤵️

Write a C program to find the Transpose of a Matrix in C, this Matrix of any order should be taken as input from the keyboard.

#### Source code⤵️

``````
#include <stdio.h>

int main()

{
int arr1,brr1,i,j,r,c;

printf("\n\nTranspose of a Matrix :\n");
printf("---------------------------\n");

printf("\nInput the rows and columns of the matrix : ");
scanf("%d %d",&r,&c);

printf("Input elements in the first matrix :\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("element - [%d],[%d] : ",i,j);
scanf("%d",&arr1[i][j]);
}
}

printf("\nThe matrix is :\n");
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<c;j++)
printf("%d\t",arr1[i][j]);
}

for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
brr1[j][i]=arr1[i][j];
}
}

printf("\n\nThe transpose of a matrix is : ");
for(i=0;i<c;i++){
printf("\n");
for(j=0;j<r;j++){
printf("%d\t",brr1[i][j]);
}
}
printf("\n\n");
return 0;
}
``````