‘C’ program to display matrix transpose.

C File =>


/* Write a ‘C’ program to read a matrix and display its transpose. */

#include<stdio.h>
int main() 
{
     int mat[30][30],trans[30][30],i,j,m,n;
 
     printf("\n Enter how many rows?");
     scanf("%d",&m);
     printf("\n Enter how many cols?");
     scanf("%d",&n);
 
     printf("\n Input matrix");
    for(i=0;i<m;i++)
   {
      for(j=0;j<n;j++)
     {
        printf("\n Enter element %d%d",i+1,j+1);
        scanf("%d",&mat[i][j]);
      }
    }
 
    printf("\n\n Given matrix is\n");
    for(i=0;i<m;i++)
   {
      for(j=0;j<n;j++)
     {
         printf("%d\t",mat[i][j]);
         trans[j][i]=mat[i][j];
      }
      printf("\n");
    }
 
     printf("\n\n Transpose of given matrix\n");
    for(i=0;i<m;i++)
   {
     for(j=0;j<n;j++)
     {
        printf("%d\t",trans[i][j]);
      }
     printf("\n");
   }
 
    return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.