Coders Packet

Transpos Of Matrix In C++ Using Arrays

By Ashwini Laxman Jadhav

In this tutorial, We will learn how to do matrix transpose using the concept of the array.

In this tutorial, we will learn about matrix transpose using arrays. The cuncept is more easier for understanding you just need to swap row<->column and your transpose matrix is ready.

Implementation Of Transpose Of Matrix In C++ Using arrays.

Consider, The matrix having values {{1 2 3},{4 5 6},{7 8 9}}

for doing Transpose you just need to observe your i^th and j^th term is there eny common thing is seems in them

Visualisation:-

    (0,1)

       |

 1   2   3                         1   4   7

 4   5   6        (1,0)-->     2   5   8 

 7   8    9                        3    6   9

Matrix before                  Matrix after

transpose                         transpose 

In both case  observe the position of   2  it has (0,1) and (1,0), So by observing this we can say that if we swap the row with column we can get transpose of any square matrices.

#include
using namespace std;

int main()
{
  int n1,n2;
  cin>>n1>>n2;
  
  int arr[n1][n2];
  
  for(int i=0;i<n1;i++)
  {
    for(int j=0;j<n2;j++)
    {
        cin>>arr[i][j];
      
    }
  }

If you want the whole source code then download it from bellow file section.

 

Download Complete Code

Comments

No comments yet