Program to obtain Transpose of a Matrix

A transpose of a matrix is formed by turning all the rows of a given matrix into columns and vice-versa. The transpose of matrix A is written as AT

Transpose of a matrix

Below is the program that will obtain transpose of 3 by 3 matrix. This program takes arr[3][3] matrix as input. It will then display its transpose matrix arrT[3][3].

#include
#include
void main(){
 int arr[3][3], arrT[3][3];
 int i,j;
 clrscr();
 printf("Enter the 3x3 matrix:\n");
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   printf("Enter the element arr[%d][%d] : ",i,j);
   scanf("%d",&arr[i][j]);
  }
 }
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   arrT[j][i] = arr[i][j];
  }
 }
 printf("The transpose of the matrix is: \n");
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   printf("\t%d",arrT[i][j]);
  }
  printf("\n");
 }
 getch();
}

Output:

Enter the 3x3 matrix:
Enter the element arr[0][0] : 1                                                 
Enter the element arr[0][1] : 2                                                 
Enter the element arr[0][2] : 3                                                 
Enter the element arr[1][0] : 4                                                 
Enter the element arr[1][1] : 5                                                 
Enter the element arr[1][2] : 6                                                 
Enter the element arr[2][0] : 7                                                 
Enter the element arr[2][1] : 8                                                 
Enter the element arr[2][2] : 9                                                 
The transpose of the matrix is:                                                 
        1       4       7                                                       
        2       5       8                                                       
        3       6       9

Also See:
2-Dimensional Array in C Programming Language

You may also like...

5 Responses

  1. Anonymous says:

    Good

  2. Anonymous says:

    This makes sense, I approve!

  3. Anonymous says:

    i think that it is a very good site to learn programming

  1. March 1, 2014

    […] symmetric matrix is a square matrix that is equal to its transpose. Let A be a symmetric matrix. Then, A = […]

  2. March 1, 2014

    […] Program to obtain Transpose of a Matrix […]

Leave a Reply

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

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet