This C++ Program which generates the transpose of a given matrix of order 3 x 3. The program initializes the matrices according to the input, creates second matrix, transposes the elements of the matrix and puts it in second matrix.
Here is source code of the C++ program which generates the transpose of a given matrix. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ program to Generate Transpose of a given 3x3 Matrix
*/
#include<iostream>
using namespace std;
int main()
{
int mat[3][3], trans_mat[3][3];
/* Initializing Mat1 and Mat2 */
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cin >> mat[i][j];
}
}
/* Transposing elements of the matrix */
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
trans_mat[j][i] = mat[i][j];
}
}
cout << "Transpose of the Given 3x3 Matrix : " << endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cout << trans_mat[i][j] << "\t";
}
cout << endl;
}
}
$ g++ main.cpp $ ./a.out Enter elements of a 3x3 Matrix : 2 3 4 3 4 5 4 5 6 Transpose of the Given 3x3 Matrix : 2 3 4 3 4 5 4 5 6
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Check Computer Science Books
- Check Programming Books
- Practice Computer Science MCQs
- Practice Programming MCQs
- Check C++ Books