Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update MatrixTranspose.cpp #770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Max-CoderBoi wants to merge 1 commit into codemistic:main from Max-CoderBoi:patch-6
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 33 additions & 37 deletions Matrix/MatrixTranspose.cpp
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,37 @@
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;

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];
}
}

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;
}
}

for (int i = 0; i < row; ++i)
for (int j = 0; j < column; ++j) {
transpose[j][i] = a[i][j];
}

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;
int row, column;
cout << "Enter rows and columns of matrix: ";
cin >> row >> column;

int a[row][column], transpose[column][row];

cout << "\nEnter elements of matrix:\n";
for (int i = 0; i < row; ++i)
for (int j = 0; j < column; ++j) {
cout << "Element a[" << i + 1 << "][" << j + 1 << "]: ";
cin >> a[i][j];
}

cout << "\nEntered Matrix:\n";
for (int i = 0; i < row; ++i) {
for (int j = 0; j < column; ++j)
cout << a[i][j] << " ";
cout << endl;
}

// Compute transpose
for (int i = 0; i < row; ++i)
for (int j = 0; j < column; ++j)
transpose[j][i] = a[i][j];

cout << "\nTranspose of Matrix:\n";
for (int i = 0; i < column; ++i) {
for (int j = 0; j < row; ++j)
cout << transpose[i][j] << " ";
cout << endl;
}

return 0;
}

AltStyle によって変換されたページ (->オリジナル) /