This is a C program for Printing the Transpose of a Matrix.
Transpose of a Matrix.
#include<stdio.h>
#include<conio.h>
void main()
{
/*declarations*/
int arr[3][3],i,j;
clrscr();
/*accept elements for the array*/
printf("Enter elements for the array \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&arr[i][j]);
}
}
/*print the original array entered by the user*/
printf("Original array entered by the user is \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d ",arr[i][j]);
}
printf("\n");
}
/*print the transpose of the array*/
printf("transpose of the array is \n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d ",arr[j][i]);
}
printf("\n");
}
getch();
}
OUTPUT:
Original array entered by the user is
1 2 3
4 5 6
7 8 9
transpose of the array is
1 4 7
2 5 8
3 6 9