Wednesday, 8 April 2015

c program for transpose of matrix

write a c program for  transpose of matrix

/* c program for  transpose of matrix */
/*author:sai                         date:8-4-2015*/

#include <stdio.h>

int main()
{
   int m, n, i, j, matrix[10][10],transpose[10][10];

   printf("Enter the number of rows and columns of matrix\n");
   scanf("%d%d", &m, &n);

   printf("Enter the elements of matrix\n");

      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 entered 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 :

No comments:

Post a Comment