Pages

When Programming is Life

Tuesday, 10 February 2015

Transpose of Matrix in C Programming

Transpose of Matrix in C Programming
Transpose of Matrix in C Programming


Hello Programmers! Welcome to Standard Programming. How many of you like doing Matrices in Math? Like it? Then there is a good news for you because today I am gonna show your guys how to find the transpose of a Matrix in C programming.

For those who don't know what Transpose of a Matrix is, if we make the columns of a matrix the row of it and vice versa then the final matrix is called the Transpose of the given Matrix. Lets say a matrix is 

1 2 1 
1 2 3
3 4 5

If we find the Transpose of this Matrix by interchanging the columns and rows it will be

1 1 3
2 2 4
1 3 5

Here we will do the same thing in C Programming with help of For Loops. Here we will run first For Loop to take the elements of the Matrix and second one to change the elements. The code is so simple than any Noob can understand. If you still have any problem understanding the code ask me in the comments, I will surely answer the questions.



#include <stdio.h>
#include <conio.h> 
int main()
{
   int m, n, c, d, matrix[10][10], transpose[10][10];
 
   printf("Enter the number of rows and columns of matrix ");
   scanf("%d%d",&m,&n);
   printf("Enter the elements of matrix \n");
 
   for( c = 0 ; c < m ; c++ )
   {
      for( d = 0 ; d < n ; d++ )
      {
         scanf("%d",&matrix[c][d]);
      }
   }
 
   for( c = 0 ; c < m ; c++ )
   {
      for( d = 0 ; d < n ; d++ )
      {
         transpose[d][c] = matrix[c][d];
      }
   }
 
   printf("Transpose of entered matrix :-\n");
 
   for( c = 0 ; c < n ; c++ )
   {
      for( d = 0 ; d < m ; d++ )
      {
         printf("%d\t",transpose[c][d]);
      }  
      printf("\n");
   }
   getch();
   return 0;
}


Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...

2 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

 
Posts RSSComments RSSBack to top
© 2011 Standard Programming ∙ Designed by BlogThietKe
Released under Creative Commons 3.0 CC BY-NC 3.0