-
Notifications
You must be signed in to change notification settings - Fork 0
/
13.c
48 lines (40 loc) · 1.15 KB
/
13.c
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
#include <stdio.h>
#define SWAP(a, b, t) t = a; a = b; b = t
#define SQUARE(a) a * a
#define SWAPWHEN(a, b, t ,cond) if (cond) SWAP(a, b, t)
int main(void) {
int tmp;
int x = 1;
int y = 2;
int z = 3;
int w = 3;
SWAP(x, y, tmp);
printf("x = %d, y = %d, tmp = %d\n", x, y, tmp);
if (x > y) SWAP(x, y, tmp);
printf("x = %d, y = %d, tmp = %d\n", x, y, tmp);
SWAPWHEN(x, y, tmp, SQUARE(1 + 2 + z++ + ++w) == 100);
printf("x = %d, y = %d\n", x, y);
printf("z = %d, w = %d, tmp = %d\n", z, w, tmp);
return 0;
}
// #define SWAP(a, b, t) \
// t = a; \
// a = b; \
// b = t
// #define SWAPWHEN(a, b, t, cond) \
// if (cond) SWAP(a, b, t)
// #define SQUARE(a) a *a
// int main() {
// int tmp;
// int x = 1;
// int y = 2;
// int z = 3;
// int w = 3;
// SWAP(x, y, tmp);
// printf("x = %d, y = %d, tmp = %d\n", x, y, tmp);
// if (x > y) SWAP(x, y, tmp);
// printf("x = %d, y = %d, tmp = %d\n", x, y, tmp);
// SWAPWHEN(x, y, tmp, SQUARE(1 + 2 + z++ + ++w) == 100);
// printf("x = %d, y = %d, tmp = %d\n", x, y, tmp);
// printf("z = %d, w = %d, tmp = %d\n", z, w, tmp);
// }