Monday, January 11, 2021

Transpose of a matrix in two dimensional array c++

 


#include<iostream>
using namespace std;
int main()
{
    int n[3][3];
    // Take input from user
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cout<<"Enter value of n["<<i<<"]"<<"["<<j<<"]"<<endl;
            cin>>n[i][j];
        }
    }
    // Show Matrix
    cout<<"Matriz is..."<<endl;
        for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cout<<n[i][j]<<"  ";
        }
        cout<<endl;
    }
    // Transpose is
    cout<<"Transpose is..."<<endl;
        for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cout<<n[j][i]<<"  ";
        }
        cout<<endl;
    }
    
    return 0;
}

No comments:

Post a Comment