Powered by Blogger.

Tuesday, February 5, 2013

Transpose Matrix

#include<iostream.h>
#include<conio.h>

class matrix
{
      int mat[10][10],t[10][10],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;
     cout<<"\nEnter Your Matrix :\n";
     for(int i=0;i<r;i++)
     {
             for(int j=0;j<c;j++)
             {
                     cout<<"\nEnter Element of ["<<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()
{
     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;
}

0 comments:

Post a Comment