-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranspose-array.cpp
More file actions
69 lines (55 loc) · 1.39 KB
/
Transpose-array.cpp
File metadata and controls
69 lines (55 loc) · 1.39 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
//CSC 160 Final Exam 3
//Purpose:
//Author: Larsen J Close Most recent changes: 5/6/16
#include <iostream> // preprocessor directive
#include <iomanip> // needed for most manipulators
using namespace std; // using directive
const int NROWS = 4;
const int NCOLS = 4;
void display( int B[][NCOLS] )
{
for(int i = 0; i < NCOLS; i++)
{
for(int x = 0; x < NROWS; x++)
{
cout << setw(4) << B[i][x];
}
cout << endl;
}
cout << "\n";
}
void transpose( int B[][NCOLS], int Q[][NCOLS])
{
for(int i = 0; i < NCOLS; i++)
{
for(int x = 0; x < NROWS; x++)
{
Q[x][i] = B[i][x];
}
}
}
int main ( void )
{
int P[][NCOLS] = {5, 3, 9, 2, 4, 1, 6, 3, 0, 8, 7, 5, 2, 6, 9, 1};
int Q[NROWS][NCOLS];
cout << "P[][] before transposing\n";
display(P);
transpose(P, Q);
cout << "Q[][] as the transpose of P[][]\n";
display(Q);
system("pause");
return 0;
} //end main ( )
/* Display of above program
P[][] before transposing
5 3 9 2
4 1 6 3
0 8 7 5
2 6 9 1
Q[][] as the transpose of P[][]
5 4 0 2
3 1 8 6
9 6 7 9
2 3 5 1
Press any key to continue . . .
*/