Wednesday, 1 March 2017

Transpose Of a Matrix In C and C++ || DEV C++ ||

#include<iostream>
using namespace std;
main()
{
int num[3][3],i,j,temp;
cout<<"Enter Numbers In Matrix:";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>num[i][j];
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i!=j)
{
temp=num[i][j];
num[i][j]=num[j][i];
num[j][i]=temp;
}
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<num[j][i]<<" ";
cout<<"\n";
}
}

No comments:

Post a Comment

Amazon1Ads