Write a C program to display transpose of matrix using user defined function.


#include<stdio.h>
#include<conio.h>
void transpose(int a[3][3],int n);
void main()
{
int a[3][3],trans[3][3];
int i,j,n;
clrscr();
printf("\n enter the limit");
scanf("\n %d",&n);
printf("\n enter the array element-");
for(i=0;i<n;i++)
 {
 for(j=0;j<n;j++)
  {
  scanf("\n %d", &a[i][j]);
  }
 }
  transpose(a,n);
getch();
}
void transpose(int a1[3][3],int n1)
{
   int trans[3][3];
   int i,j;
for(i=0;i<n1;i++)
 {
 for(j=0;j<n1;j++)
  {
  trans[i][j]=a1[j][i];
  }
 }
printf("\n the transpose of matrix is\n-");
for(i=0;i<n1;i++)
 {
 for(j=0;j<n1;j++)
  {
  printf("\t %d",trans[i][j]);
  }
 printf("\n");
}
getch();
}

/* Output
 enter the limit-3
 enter the array element-
        1 2 3
        4 5 6
        7 8 9

 the transpose of matrix is
         1       4       7
         2       5       8
         3       6       9 */