Write a C++ program to find the transpose of a given matrix of size mxn, where m and n are interned by the user.




 Program Code:
#include<iostream>
using namespace std;
int main()
{
int a[15][15],b[15][15];
int i,j,m,n;
cout<<"Enter number of row in the given matrix : ";
cin>>m;
cout<<endl;
cout<<"Enter number of column in the given matrix : ";
cin>>n;
cout<<endl;
cout<<"Enter elements in an matrix : ";
cout<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"Input for the given matrix is : ";



for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
b[i][j]=a[j][i];
}
}
cout<<"Transpose of the given matrix : ";
cout<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<b[i][j]<<" ";
}
cout<<endl;
}
return 0;
}





The Program output is tested on www.jdoodle.com
Output:
Enter number of row in the given matrix : 3
Enter number of column in the given matrix : 3
Enter elements in an matrix : 1 2 3 4 5 6 7 8 9
Input for the given matrix is : 
1 2 3 
4 5 6 
7 8 9 
Transpose of the given matrix : 
1 4 7 
2 5 8 
3 6 9 





Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: