Computer Science, asked by geetanjalibedre2785, 10 months ago

A c++ Program for 2d matrix for taking Transpose

Answers

Answered by skmusical18
0

#include<iostream>

using namespace std;

int main ()

{

int A[10][10], m, n, i, j;

cout << "Enter rows and columns of matrix : ";

cin >> m >> n;

cout << "Enter elements of matrix : ";

for (i = 0; i < m; i++)

for (j = 0; j < n; j++)

cin >> A[i][j];

cout << "Entered Matrix : \n ";

for (i = 0; i < m; i++)

{

for (j = 0; j < n; j++)

cout << A[i][j] << " ";

cout << "\n ";

}

cout << "Transpose of Matrix : \n ";

for (i = 0; i < n; i++)

{

for (j = 0; j < m; j++)

cout << A[j][i] << " ";

cout << "\n ";

}

return 0;

}

Program Explanation

1. The user is asked to enter the number of rows and columns of the matrix.

2. The elements of the matrix are asked to enter and stored in the matrix ‘A’.

3. The transpose is found by exchanging the rows with columns and columns with rows.

4. The original matrix and the transpose are both printed.

Similar questions