The program takes an input matrix from the user, computes the transpose of the matrix, and then prints the transpose. The transpose of a matrix is obtained by interchanging the rows and columns of the original matrix.
Here's how the program works:
Overall, the program is correct and should work as expected. However, there is one issue with the program - it assumes that the maximum size of the matrix is 10x10. If the user enters a larger matrix size, the program will not work correctly. To fix this, the program should dynamically allocate memory for the matrix based on the user's input.
#include<iostream> using namespace std; int main() { int matrix1[10][10],matrix2[10][10],row,col; cout<<"\nEnter the number of rows: "; cin>>row; cout<<"\nEnter the number of columns: "; cin>>col; cout<<"\nEnter elements of matrix: "<<endl; for(int i=0;i<row;i++) { for(int j=0;j<col;j++) { cin>>matrix1[i][j]; } } for(int i=0;i<row;i++) { for(int j=0;j<col;j++) { matrix2[j][i]=matrix1[i][j]; } } cout<<"Transpose of Matrix: "<<endl; for(int i=0;i<col;i++) { for(int j=0;j<row;j++) { cout<<matrix2[i][j]<<" "; if(j==row-1) cout<<endl; } } return 0; }To download raw file Click Here
Enter the number of rows: 2 Enter the number of columns: 2 Enter elements of matrix: 1 2 3 4 Transpose of Matrix: 1 3 2 4
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions