-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranspose.cpp
More file actions
41 lines (35 loc) · 832 Bytes
/
Copy pathtranspose.cpp
File metadata and controls
41 lines (35 loc) · 832 Bytes
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
#include <iostream>
using namespace std;
int main () {
int n, m;
cin >>n >> m;
int arr[n][m];
for (int i = 0; i< n;i++){
for(int j = 0; j < m;j++){
cout << "Giving input for " << i << " " << j <<" : " ;
cin >> arr[i][j];
}
}
for (int i = 0; i< n;i++){
for(int j = 0; j < m;j++){
cout << arr[i][j] << " ";
}
cout << endl;
}
cout << endl;
cout << endl;
cout << "Transpose :" << endl << endl;
for(int i = 0; i< n;i++){
for(int j = i;j<m;j++){
int temp = arr[i][j];
arr[i][j] = arr[j][i];
arr[j][i] = temp;
}
}
for (int i = 0; i< n;i++){
for(int j = 0; j < m;j++){
cout << arr[i][j] << " ";
}
cout << endl;
}
}