Announcement:

This is just the beginning of this blog, please don't copy any of my posts.

Friday 6 September 2013

[Write a] C Program to Print the Transpose of 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.



Program

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

   void main()
    {
      int m1[10][10],tr[10][10],i,j,r,c;
      clrscr();
      printf("\n How many rows & columns in the matrix");
      scanf("%d%d",&r,&c);
      puts("\n Enter the elements:");
      for(i=0;i<r;i++)
for(j=0;j<c;j++)
 {
   scanf("%d",&m1[i][j]);
   tr[j][i]=m1[i][j];
 }
printf("\nThe transpose is:\n");
for(i=0;i<c;i++)
 {
   for(j=0;j<c;j++)
    printf("%d",tr[i][j]);
    printf("\n");
 }
printf("\n");
getch();
      }

Output:
How many rows and columns of matrix
2
3
Enter the elements 
1
2
3
4
4
5
The transpose is:
140
240
340
Share it Please

Pankaj Gaikar

Pankaj Gaikar is a professional blogger from Pune, India who writes on Technology, Android, Gadgets, social media and latest tech updates at Punk Tech , Being Android & Shake The Tech . Email me HERE

0 comments :

Post a Comment

Copyright @ 2013 Pune University Bachelor of Engineering . Designed by Pankaj Gaikar | Love for The Tricks Machine