Site icon DataFlair

C Program to Print Transpose of a Matrix

Program 1

// Program for Transpose of Matrix
#include<stdio.h>
#include<conio.h>
int main()
{
    int a[50][50],r,c,m,n;
    printf("Enter the values of Rows and Cols");
    scanf("%d %d",&m,&n);
    printf("Enter elements in matrix");
    for(r=0;r<m;r++)
    {
        for(c=0;c<n;c++)
        scanf("%d",&a[r][c]);
    }
    for(r=0;r<m;r++)
    {
        for(c=0;c<n;c++)
        { 
            printf("%5d",a[r][c]);
        }
     printf("\n\n");
    }
 printf("\n Transpose of Matrix is : \n");
    for(r=0;r<m;r++)
    {
        for(c=0;c<n;c++)
        { 
            printf("%5d",a[c][r]);
        }
     printf("\n\n");
    }
    return 0;
}

 

Exit mobile version