Transpose of Matrix C++

//Transpose of Matrix C++
#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type int
int a[3][3],i,j;
//Input the numbers
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<"Enter number :";
cin>>a[i][j];
}
}
//Display the original matrix
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<"t";
}
cout<<endl;
}
cout<<"Transpose of above matrix is :-"<<endl;
//Display the transpose matrix
for(j=0;j<3;j++)
{
for(i=0;i<3;i++)
{
cout<<a[i][j]<<"t";
}
cout<<endl;
}
//get character
getch();
}

Output

Enter the number
1
Enter the number
2
Enter the number
3
Enter the number
4
Enter the number
5
Enter the number
6
Enter the number
7
Enter the number
8
Enter the number
9
1 2 3
4 5 6
7 8 9
Transpose of above matrix is :-
1 4 7
2 5 8
3 6 9
Previous Post Next Post