Wednesday, September 7, 2016

PROGRAM TO FIND TRANSPOSE OF A MATRIX

PROGRAM TO FIND TRANSPOSE OF A MATRIX.

#include <iostream>
using namespace std;
int main()
{
    int a[20][20],i,j,m,n;
    cout<<"Enter No. of Rows and Columns of Matrix: ";
    cin>>m>>n;
    cout<<"\nEnter "<<(m*n)<<" Elements of Matrix: ";
    for(i=1; i<=m; i++)
    {
        for(j=1; j<=n; j++)
            cin>>a[i][j];
    }

    cout<<"\nMatrix is:\n";
    for(i=1; i<=m; i++)
    {
        for(j=1; j<=n; j++)
        {
            cout<<a[i][j];
            cout<<'\t';
        }
        cout<<'\n';
    }

    cout<<"\nTranspose of Matrix is:\n";
    for(j=1; j<=n; j++)
    {
        for(i=1; i<=m; i++)
        {
            cout<<a[i][j];
            cout<<'\t';
        }
        cout<<'\n';
    }
    return 0;
    }