I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.
#include <iostream>
using namespace std;
int main()
{
static int array[10][10];
int i, j, m, n;
cout<<"Enter the order of the matrix \n";
// Inputing elements in matrix from user
cin>>m>>n;
cout<<"Enter the coefiicients of the matrix\n";
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
cin>>array[i][j];
}
}
//Printing the original matrix
cout<<"The given matrix is \n";
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
cout<<" "<<array[i][j];
}
cout<<"\n";
}
//Printing the transpose of matrix
cout<<"Transpose of matrix is \n";
for (j = 0; j < n; ++j)
{
for (i = 0; i < m; ++i)
{
cout<<" "<<array[i][j];
}
cout<<"\n";
}
return 0;
}
I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.
Result:
Enter the order of the matrix
3
3
Enter the coefiicients of the matrix
1
2
3
4
5
6
7
8
9
The given matrix is
1 2 3
4 5 6
7 8 9
Transpose of matrix is
1 4 7
2 5 8
3 6 9
need an explanation for this answer? contact us directly to get an explanation for this answer