Search This Blog

Program to Find Transpose of a Matrix

This is a c program to find the transpose of a matrix. Finding transpose of a matrix is simple like displaying the matrix. You just have to interchange i and j at the matrix indices.
#include<stdio.h>
int main()
{
    int m, n, i, j;
    int mat[10][10], trans[10][10];
    printf("Enter the number of rows and columns of matrix\n");
    scanf("%d%d",&m,&n);
    printf("\nEnter the elements of matrix \n");
    for( i = 0 ; i < m ; i++ )
        {
        for( j = 0 ; j < n ; j++ )
            scanf("%d", &mat[i][j] );
        }

    for( i = 0 ; i<m ; i++ )
        {
        for( j = 0 ; j < n ; j++ )
            trans[j][i] = mat[i][j];
        }
    printf("Transpose is:\n ");
    for( i = 0 ; i < n ; i++ )
        {
        printf("\n");
        for( j = 0 ; j < m ; j++ )
            printf("%d\t ", trans[i][j] );
        }
}

No comments: