Praveen | Typing Speed Test is a very useful Software available for free Download.

C Programs to Transpose Matrix

      This c program prints transpose of a matrix. It is obtained by interchanging rows and columns of a matrix. When we transpose a matrix then the order of matrix changes, but for a square matrix order remains same.


C programming code

#include<stdio.h>
#include<conio.h>


void main()
{
   int a[3][3], t[3][3], i, j, m, n;
   clrscr();
   printf("\n Enter the number of rows and columns of matrix ");
   scanf("%d%d",&m,&n);
   printf("\n Enter the elements of matrix \n");
   for( i = 0 ; i < m ; i++ )
   {
      for( j = 0 ; j < n ; j++ )
      {
         scanf("%d",&a[i][j]);
      }
   }

   for( i = 0 ; i < m ; i++ )
   {
      for( j = 0 ; j < n ; j++ )
      {
         t[j][i] = a[i][j];
      }
   }

   printf("\n Transpose of entered matrix :-\n");

   for( i = 0 ; i < n ; i++ )
   {
      for( j = 0 ; j < m ; j++ )
      {
         printf("%d\t",t[i][j]);
      } 
      printf("\n");
   }
   getch();
}


Output:-