-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayTraverse.cpp
More file actions
42 lines (40 loc) · 866 Bytes
/
Copy patharrayTraverse.cpp
File metadata and controls
42 lines (40 loc) · 866 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
42
#include <iostream>
using namespace std;
int main()
{
int row = 3;
int col = 4;
int arr[row][col] = {
{1, 3, 4, 5},
{5, 7, 8, 2},
{0, 1, 4, 8}};
cout << "Before traverse: " << endl;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
cout << " " << arr[i][j] << " ";
}
cout << endl;
}
int brr[col][row];
// traverse start
for (int i = 0; i < col; i++)
{
for (int j = 0; j < row; j++)
{
brr[i][j] = arr[j][i];
}
}
// traverse end
cout << "After traverse: " << endl;
for (int i = 0; i < col; i++)
{
for (int j = 0; j < row; j++)
{
cout << " " << brr[i][j] << " ";
}
cout << endl;
}
return 0;
}