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
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
Good
This makes sense, I approve!
i think that it is a very good site to learn programming