Write a C++ Program to Find Transpose of a Matrix

C++ Program to Find Transpose of a Matrix

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C++ programming concepts. You can learn C++ language at your own speed and time. One can learn concepts of C++ language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

C++ Program to Find Transpose of a Matrix
C++ Program to Find Transpose of a Matrix

Write a C++ Program to Find Transpose of a Matrix

PROGRAM:C++ Program to Find Transpose of a Matrix

/* C++ Program to Find Transpose of a Matrix*/

#include <iostream>
using namespace std;

int main() {
int a[10][10], transpose[10][10], row, column, i, j;

cout << “Enter rows and columns of matrix: “;
cin >> row >> column;

cout << “\nEnter elements of matrix: ” << endl;

// Storing matrix elements
for (int i = 0; i < row; ++i) {
for (int j = 0; j < column; ++j) {
cout << “Enter element a” << i + 1 << j + 1 << “: “;
cin >> a[i][j];
}
}

// Printing the a matrix
cout << “\nEntered Matrix: ” << endl;
for (int i = 0; i < row; ++i) {
for (int j = 0; j < column; ++j) {
cout << ” ” << a[i][j];
if (j == column – 1)
cout << endl << endl;
}
}

// Computing transpose of the matrix
for (int i = 0; i < row; ++i)
for (int j = 0; j < column; ++j) {
transpose[j][i] = a[i][j];
}

// Printing the transpose
cout << “\nTranspose of Matrix: ” << endl;
for (int i = 0; i < column; ++i)
for (int j = 0; j < row; ++j) {
cout << ” ” << transpose[i][j];
if (j == row – 1)
cout << endl << endl;
}

return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *