Computer Science, asked by john15588, 1 year ago

write a c++ program to find the transpose of a matrix using two dimensional array​

Answers

Answered by skmusical18
1

#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