click on this link......

LinkGrand.com

Friday 6 December 2013

Program to find Transpose of a matrix


This c program prints transpose of a matrix. It is obtained by interchanging rows and columns of a matrix. For example if a matrix is
1 2
3 4
5 6
then transpose of above matrix will be
1 3 5
2 4 6
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 row, col, i, j, matrix[10][10], transpose[10][10];

 

   printf("Enter the number of rows and columns of matrix ");

   scanf("%d%d",&row,&col);

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

 

   for( i = 0 ; i < row ; i++ )

   {

      for( j = 0 ; j < col ; j++ )

      {

         scanf("%d",&matrix[i][j]);

      }

   }

 

   for( i = 0 ; i < row ; i++ )

   {

      for( j = 0 ; j < col ; j++ )

      {

         transpose[j][i] = matrix[i][j];

      }

   }

 

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

 

   for( i = 0 ; i < col ; i++ )

   {

      for( j = 0 ; j < row ; j++ )

      {

         printf("%d\t",transpose[i][j]);

      } 

      printf("\n");

   }

 

   getch();

}

 


No comments:

Post a Comment