C program to display the transpose of given 3 X 3 matrix

How to write a C program to display the transpose of given 3 X 3 matrix in C Programming Language ?


Solution:
/*C program to display the transpose of given 3 X 3 matrix*/
#include<stdio.h>
#include<conio.h>
  void main()
{
  int a[10][10],b[10][10],i,j;
  clrscr();
  printf("\nEnter the elements of matrix:");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  scanf("%d",&a[i][j]);
}
}
  printf("\nThe Transpose of matrix is:\n");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  b[i][j]=a[j][i];
  printf("\t%d\t",b[i][j]);
}
  printf("\n");
}
  getch();
}

//OUTPUT:
//Enter the elements of matrix:
    1 2 3 4 5 6 7 8 9
//The Transpose of matrix is:
    1 4 7
    2 5 8
    3 6 9


Learn More :