-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix_play.cpp
More file actions
93 lines (79 loc) · 2.1 KB
/
matrix_play.cpp
File metadata and controls
93 lines (79 loc) · 2.1 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
using namespace std;
int main(){
int n, m;
cout<<"Enter the size of matrix row X column: ";
cin>>n>>m;
int mat[n][m];
cout<<"The input matrix is: "<<endl;;
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
cin>>mat[i][j];
}
}
cout<<"The matrix inputted is: "<<endl;
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
cout<<mat[i][j]<<" ";
}
cout<<endl;
}
// //move elements of top row
// for (int j=0; j<m; j++){
// mat[n][j+1] = mat[n][j];
// }
// //move elements if last column
// for (int i=n; i>0; i--){
// mat[i-1][m] = mat[i][m];
// }
// //move elements of last row
// for(int j=m; j>0; j--){
// mat[n][j-1] = mat[n][j];
// }
// //move elements of first column
// for (int i=0; i<n; i++){
// mat[i+1][m] = mat[i][m];
// }
// cout<<"The new matrix after rotation is:"<<endl;
// for (int i=0; i<n; i++){
// for (int j=0; j<m; j++){
// cout<<mat[i][j]<<" ";
// }
// cout<<endl;
// }
int transpose[n][m];
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
transpose[j][i] = mat[i][j];
}
}
cout<<"The transpose of the matrix is:"<<endl;
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
cout<<transpose[i][j]<<" ";
}
cout<<endl;
}
int row_switch[n][m];
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
row_switch[j][i] = mat[i][j];
}
}
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
row_switch[i+1][j] = row_switch[i][j];
if(i==n-1){
row_switch[0][j] = row_switch[i][j];
}
}
}
cout<<"After Switching rows: "<<endl;
for (int i=0; i<n; i++){
for (int j=0; j<m; j++){
cout<<row_switch[i][j]<<" ";
}
cout<<endl;
}
return 0;
}