Wednesday, March 20, 2013

Transpose Of A Matrix

Transpose is a matrix operation in which all the rows of a matrix is converted to its columns and columns
to its rows............


Program:

#include<iostream>

using namespace std;


int main()
{
            system("cls");
                            cout<<setw(54)<<"*****--------------------*****\n";
                            cout<<setw(54)<<"*****TRANSPOSING A MATRIX*****\n";
                            cout<<setw(54)<<"*****--------------------*****\n";
                            cout<<"\n\n";
                            int a[30][30],b[30][30],m,n,i,j;
                            cout<<"\tEnter row size: ";
                            cin>>m;
                            cout<<"\tEnter column size: ";
                            cin>>n;
                            cout<<"\n\nEnter matrix elements : \n\n";
                            for(i=0;i<m;++i)
                            {
                                for(j=0;j<n;++j)
                                {
                                    cout<<"Enter ["<<i<<"]["<<j<<"] : ";
                                    cin>>a[i][j];
                                }
                            }
                            Sleep(1000);
                            system("cls");
                            cout<<"\n\n\n\t\t\tThe Matrix Is : \n\n";
                            for(i=0;i<m;++i)
                            {
                                cout<<"\t\t\t";
                                 for(j=0;j<n;++j)
                                 {
                                    cout<<a[i][j]<<" ";
                                 }
                                 cout<<endl;
                            }
                            cout<<"\n\n\t\t\tTranspossing........";
                            Sleep(2200);
                            for(i=0;i<n;++i)
                            {
                                 for(j=0;j<m;++j)
                                 {
                                      b[i][j]=a[j][i];
                                 }
                            }
                            cout<<"\n\n\t\t\tThe Transposed Matrix Is : \n\n";
                            for(i=0;i<n;++i)
                            {
                                cout<<"\t\t\t";
                                 for(j=0;j<m;++j)
                                 {
                                    cout<<b[i][j]<<" ";
                                 }
                                 cout<<endl;
                            }
                            return 0;
}



Output:



0 comments:

Post a Comment