-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemonstrate-array-swaps.cpp
More file actions
59 lines (44 loc) · 1.31 KB
/
Demonstrate-array-swaps.cpp
File metadata and controls
59 lines (44 loc) · 1.31 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
//CSC 160 Quiz 3 part B
//Purpose: Write program for three functions with array
//Author: Larsen J Close Most recent changes: 4/22/16
#include <iostream> // preprocessor directive
#include <iomanip> // needed for most manipulators
using namespace std; // using directive
void display(double x[], int y)
{
for( int t = 0; t<y ; t++)
{
cout << setw(5) << x[t];
}
}
void exchange(double z[], int q, int w)
{
swap(z[q], z[w]);
}
int main ( void )
{
const int N = 7;
double p[N] = {1.2, 4.3, 2.7, 9.1, 6.8, 3.4, 7.5};
cout << "\n p array before exchange\n";
display(p, N);
//use exchange to swap positions of p[2] and p[5]
exchange(p, 2, 5);
cout << "\n p array after first exchange\n";
display(p, N);
//use exchange to swap 6-1
exchange(p, 6, 1);
cout << "\n p array after second exchange\n";
display(p, N);
system("pause");
return 0;
} //end main ( )
/* Display of above program
Max value in the data array is 92
p array before exchange
1.2 4.3 2.7 9.1 6.8 3.4 7.5
p array after first exchange
1.2 4.3 3.4 9.1 6.8 2.7 7.5
p array after second exchange
1.2 7.5 3.4 9.1 6.8 2.7 4.3
Press any key to continue . . .
*/