-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTranspose.cpp
52 lines (46 loc) · 1.03 KB
/
Transpose.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
This C++ program prints transpose of a matrix.
It is obtained by interchanging rows and columns of a matrix.
For example if a matrix is
1 2
3 4
5 6
then transpose of above matrix will be
1 3 5
2 4 6
When we transpose a matrix then the order of matrix changes, but for a square matrix order remains same.
*/
#include<iostream.h>
#include<conio.h>
main()
{
int m, n, c, d, matrix[10][10], transpose[10][10];
cout<<"Enter the number of rows and columns of matrix ";
cin>>m>>n;
cout<<"Enter the elements of matrix \n";
for( c = 0 ; c < m ; c++ )
{
for( d = 0 ; d < n ; d++ )
{
cin>>matrix[c][d];
}
}
for( c = 0 ; c < m ; c++ )
{
for( d = 0 ; d < n ; d++ )
{
transpose[d][c] = matrix[c][d];
}
}
cout<<"Transpose of entered matrix :-\n";
for( c = 0 ; c < n ; c++ )
{
for( d = 0 ; d < m ; d++ )
{
cout<<" "<<transpose[c][d];
}
cout<<endl;
}
getch();
return 0;
}