Transpose of Matrix using C++ Programming Language

Program Code:

#include<iostream>
using namespace std;

int main()
{
    int  a[2][2],b[2][2] ;
cout<<"*********************************"<<endl;
cout<<"Transpose of Matrix"<<endl;
cout<<"*********************************"<<endl<<endl;
cout<<"Enter Elements of 2*2 Matrix A :"<<endl;
for(int i=0;i<2;i++)
{
for(int j = 0;j<2;j++)
{
cin>>a[i][j];
}

}

cout<<endl<<"Matrix A =  "<<endl;
for(int i=0;i<2;i++)
{
for(int j = 0;j<2;j++)
{
cout<<" \t\t "<<a[i][j]<<"  ";
}
cout<<endl;
}

cout<<endl<<endl;
for(int i=0;i<2;i++)
{
for(int j = 0;j<2;j++)
{
b[i][j]=a[j][i];
}
}

cout<<endl<<endl<<"Transpose of a matrix A is  =  "<<endl;
for(int i=0;i<2;i++)
{
for(int j = 0;j<2;j++)
{
cout<<" \t\t "<<b[i][j]<<"  ";
}
cout<<endl;
}
return 0;

}

Output:



No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.