-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path250-switcher.c
More file actions
66 lines (63 loc) · 1.16 KB
/
250-switcher.c
File metadata and controls
66 lines (63 loc) · 1.16 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
#include <stdio.h>
#include <stdlib.h>
#if 0
/* $begin 250-switcher-prob-c */
void switcher(long a, long b, long c, long *dest)
{
long val;
switch(a) {
case ___: /* Case A */
c = _____;
/* Fall through */
case ___: /* Case B */
val = _____;
break;
case ___: /* Case C */
case ___: /* Case D */
val = _____;
break;
case ___: /* Case E */
val = _____;
break;
default:
val = _____;
}
*dest = val;
}
/* $end 250-switcher-prob-c */
#endif
/* $begin 250-switcher-ans-c */
void switcher(long a, long b, long c, long *dest)
{
long val;
switch(a) {
case 5:
c = b ^ 15;
/* Fall through */
case 0:
val = c + 112;
break;
case 2:
case 7:
val = (c + b) << 2;
break;
case 4:
val = a;
break;
default:
val = b;
}
*dest = val;
}
/* $end 250-switcher-ans-c */
int main(int argc, char *argv[]) {
long args[3] = {1, 2, 3};
int i;
long val;
for (i = 0; i < 3 && i < argc-1; i++)
args[i] = atoi(argv[i+1]);
switcher(args[0], args[1], args[2], &val);
printf("Switcher(%ld, %ld, %ld) --> %ld\n",
args[0], args[1], args[2], val);
return 0;
}