#include <iostream>
using namespace std;
const int MAX = 10;
int main() {
int matrix[MAX][MAX], transpose[MAX][MAX];
int rows, cols, i, j;
cout << "Enter number of rows and columns of matrix: ";
cin >> rows >> cols;
cout << "Enter elements of matrix:" << endl;
for(i=0; i<rows; i++) {
for(j=0; j<cols; j++) {
cin >> matrix[i][j];
}
}
for(i=0; i<rows; i++) {
for(j=0; j<cols; j++) {
transpose[j][i] = matrix[i][j];
}
}
cout << "Transpose of matrix:" << endl;
for(i=0; i<cols; i++) {
for(j=0; j<rows; j++) {
cout << transpose[i][j] << " ";
}
cout << endl;
}
return 0;
}
* In this program, we declare two 2D arrays matrix and transpose of size MAX x MAX. We also declare variables for the number of rows and columns in the matrix.
* We then take input from the user for the elements of the matrix using nested for loops.
* Next, we find the transpose of the matrix by interchanging the rows and columns of the original matrix. This is done using another nested for loop, where we copy the elements of the matrix to the transpose matrix.
* Finally, we print the transpose of the matrix using nested for loops.
Enter number of rows and columns of matrix: 2 3
Enter elements of matrix:
1 2 3
4 5 6
Transpose of matrix:
1 4
2 5
3 6