c program to find transpose of a matrix
C Programming

C Program to find Transpose of a Matrix

C Program to find Transpose of a Matrix 

Write a Program in C to find the Transpose of a Given Matrix . Matrix Transpose program in C is generally asked in University exam of C Programming subject. In this tutorial transpose of a matrix program is explained with output and program.

Transpose of a matrix is obtained by interchanging the rows of matrix with columns and vice versa.

This program will be beneficial for students.

Algorithm for Transpose of a Matrix in C 

Step 1 – First we declare  two variables m and n for number of rows and columns, input matrix  matrix[10][10] , transpose[10][10].

Step 2 – Input the value of m and n.

Step 3 – Input the elements of matrix using nested loops

Step 4 – To find the transpose of a matrix we interchange the row and column of the given matrix and store it in transpose matrix.

Step 5 – Print the elements transpose matrix using nested loop.

C Program to find the Transpose of a matrix  is given here

#include <stdio.h>

int main()

{

int m, n, i, j, matrix[10][10], transpose[10][10];
printf(“Enter rows and columns :”);
scanf(“%d%d”, &m, &n);
printf(“Enter elements of the matrix”);
for (i= 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
scanf(“%d”, &matrix[i][j]);
}
}
for (i = 0;i < m;i++)
{
for (j = 0; j < n; j++)
{
transpose[j][i] = matrix[i][j];
}
}
printf(“Transpose of the matrix:\n”);
for (i = 0; i< n; i++)
{
for (j = 0; j < m; j++)
{
printf(“%d\t”, transpose[i][j]);
}
printf(“\n”);
}
return 0;
}

Output

matrix transpose program in c

Conclusion and Summary

In this tutorial, we learnt about c program to find transpose of a matrix and algorithm steps.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *