on Leave a Comment

C++ Program to Find Transpose of a Matrix



This article contains C++ programming code to transpose a matrix.

C++ Program to Find Transpose of a Matrix

#include<iostream>
using namespace std;
int main()
{
        int a[3][3], i, j, t[3][3];
        cout<<"Enter elements of array (3*3): ";
        for(i=0; i<3; i++)
        {
                for(j=0; j<3; j++)
                {
                        cin>>a[i][j];
                }
        }
        for(i=0; i<3; i++)
        {
                for(j=0; j<3; j++)
                {
                        t[i][j]=a[j][i];
                }
        }
        cout<<"Transpose of the Matrix is :\n";
        for(i=0; i<3; i++)
        {
                for(j=0; j<3; j++)
                {
                        cout<<t[i][j]<<"\t";
                }
                cout<<"\n";
        }
        return 0;
}

OUTPUT:

Enter elements of array (3*3): 1
2
3
1
2
3
1
2
3
Transpose of the Matrix is :
1       1       1
2       2       2
3       3       3

See also:




0 comments:

Post a Comment