Transpose of Matrix – C Program

Transpose of Matrix – C Program

write a c program to convert given matrix to transpose matrix form.

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

void main()
{
 int a[10][10],i,j,m, row, col,

printf("Enter the row size of matrix : \n");
scanf("%d",&row);
 
printf("Enter the column size of matrix : \n\n");
scanf("%d",&col);

printf("Enter the elements of Matrix matrix :\n");
 for(i=0;i<row;i++)
 {
    for(j=0;j<col;j++)
    {    
       scanf("%d",&a[i][j]);
    }
 }
 
 printf("\nThe Original Matrix is : \n\n");
 for(i=0;i<row;i++)
 {
  for(j=0;j<col;j++)
    {
     printf("%d",a[i][j]);
     printf("\t");
    }
  print(\n);
 } 
 for(i=0;i<row;i++)
 {
  for(j=i+1;j<col;j++)
  {
   m=a[i][j];
   a[i][j]=a[j][i];
   a[j][i]=m;
  }
 }

 printf("\nThe Transposed Matrix is : \n\n");
 for(i=0;i<row;i++)
 {
  for(j=0;j<col;j++)
    {
     printf("%d",a[i][j]);
     printf("\t");
    }
  print(\n);
 }
getch();
}

The output of matrix transpose is :

Enter the row size of matrix :
3

Enter the column size of matrix :
3

Enter the elements of Matrix matrix :
1
2
3
4
5
6
7
8
9

The Original Matrix is :

1  2  3
4  5  6
7  8  9

The Transposed Matrix is :

1  4  7
2  5  8
3  6  9

 

Author: Meera Academy

Leave a Reply

Your email address will not be published. Required fields are marked *