-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathch1_max3.cpp
More file actions
64 lines (61 loc) · 1.18 KB
/
ch1_max3.cpp
File metadata and controls
64 lines (61 loc) · 1.18 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
#include <stdio.h>
void max3(int &x, int &y, int &z)
{
int temp;
if (x>y){
if (x>z){ // x > y & x > z
if (y>z){
return;
}
else{
temp = y;
y = z;
z = temp;
return;
}
}
else{ // z > x > y
temp = x;
x = z;
z = temp;
temp = y;
y = z;
z = temp;
}
}
else{
if (x<z) { // x<y, x<z
if (y>z){
// y>z>x
temp = x;
x = y;
y = temp;
temp = z;
z = y;
y = temp;
}
else{
// x < y < z
temp = z;
z = x;
x = temp;
}
}
else {
// z<x<y
temp = x;
x = z;
z = temp;
temp = y;
y = z;
z = temp;
}
}
}
int main()
{
int x, y, z;
x = 400000; y = -4; z = 1000;
max3(x, y, z);
printf("x = %d, y = %d, z = %d\n", x, y, z);
}