In this c++ program we are going to take transpose of a matrix. Transpose of matrix include transforming rows into columns and columns into rows.
In this program we will take an array of five rows and five columns and another array named transpose in which we will store the result of transformation.
Program:
// Program By http://solutionscpp.blogspot.com// Author Mansoor Ahmed
// GMail ID: secguy000@gmail.com
#include<iostream>
using namespace std;
int main()
{
int arr[5][5], transpose[5][5];
int rows=0, columns=0;
cout<<"Enter total number of Rows: ";
cin>>rows;
cout<<"Enter total number of Columns: ";
cin>>columns;
for(int i=0;i<rows;i++)
{
for(int j=0;j<columns;j++)
{
cin>>arr[i][j];
}
}
cout<<"Printing Matrix" <<endl;
for(int i=0;i<rows;i++)
{
for(int j=0;j<columns;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
// Finding Transpose of Matrix
for(int i=0;i<rows;i++)
{
for(int j=0;j<columns;j++)
{
transpose[j][i]=arr[i][j];
}
cout<<endl;
}
//Displaying The Final Result
cout<<"Transpose of Entered Matrix is: " <<endl;
for(int i=0;i<columns;i++)
{
for(int j=0;j<rows;j++)
{
cout<<transpose[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
0 comments: