#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class matrix
{
int **mat,**t,r,c;
public:
void getmat();
void transpose();
void display();
};
void matrix::getmat()
{
cout<<"\nEnter the size of Matrix : ";
cout<<"\nRow : ";
cin>>r;
cout<<"\nColumn : ";
cin>>c;
mat=new int *[r];
for(int i=0;i<r;i++)
mat[i]=new int [c];
cout<<"\nEnter Your Matrix :\n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<"\nEnter Element ["<<i+1<<"]["<<j+1<<"] : ";
cin>>mat[i][j];
}
}
}
void matrix::display()
{
cout<<"\nThe Original Matrix : \n";
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<mat[i][j]<<"\t";
}
cout<<endl;
}
}
void matrix::transpose()
{
t=new int *[c];
for(int i=0;i<c;i++)
t[i]=new int [r];
cout<<"\nThe Transpose Matrix : \n";
for(int i=0;i<c;i++)
{
for(int j=0;j<r;j++)
{
t[i][j]=mat[j][i];
cout<<t[i][j]<<"\t";
}
cout<<endl;
}
}
int main()
{
matrix M;
M.getmat();
M.display();
M.transpose();
getch();
return 0;
}
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment