Transpose: Transpose of a Matrix means changing Rows into Columns and vice-versa.
Statement of C Program: This Program accepts the Matrix and prints its Transpose.
#include<stdio.h>
#include<conio.h>
void main()
{
int A[2][3] , B[3][2];
int i, j; /* 'i' used for rows and 'j' used for columns */
clrscr();
printf(" Enter the elements of A\n");for(i=0 ; i<2 ; i++)
{
for(j=0 ; j<3 ; j++)
{
scanf("%d" , &A[i][j] );
}
}
printf(" Matrix is\n");
for(i=0 ; i<2 ; i++)
{
for(j=0 ; j<3 ; j++)
{
printf("%d\t" , A[i][j] ); /* '\t' used for Tab */
}
printf("\n"); /* '\n' used for next line character */
}
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<2 ; j++)
{
B[i][j] = A[j][i];
}
}
printf(" After Transpose\n");
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<2 ; j++)
{
printf("%d\t" , B[i][j] );
}
printf("\n");
}
getch();
} /* End of main */
Output:
Enter the elements of A
4
6
3
9
1
7
Matrix is
4 6
3 9
1 7
After Transpose
4 3 1
6 9 7
That's All
0 Response to "Write a C Program to Print the Transpose of a Matrix"
Post a Comment