-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch04s03.c
More file actions
68 lines (59 loc) · 1.27 KB
/
ch04s03.c
File metadata and controls
68 lines (59 loc) · 1.27 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
#include <stdio.h>
void first(int x)
{
if (x > 0 && x < 10);
else
printf("x is out of range.\n");
if (x <= 0 || x >= 10)
printf("x is out of range.\n");
}
void second(int x, int y)
{
if (x > 0)
printf("Test OK!\n");
else if (x <= 0 && y > 0)
printf("Test OK!\n");
else
printf("Test failed!\n");
if (x <= 0 && y <= 0)
printf("Test failed!\n");
else
printf("Test OK!\n");
}
void third(int x, int y)
{
if (x > 1 && y != 1) {
printf("1\n");
} else if (x < 1 && y != 1) {
printf("2\n");
} else {
printf("3\n");
}
if (x > 1 && y != 1) {
printf("1\n");
} else if (x < 1 && y != 1) {
printf("2\n");
} else if (x == 1) { //错误,应为x == 1 || y == 1
printf("3\n");
}
}
void forth(int x, int y, int z)
{
if (x < 3 && y > 3)
printf("Test OK!\n");
else if (x >= 3 && y >= 3) //可删除
printf("Test OK!\n");
else if (z > 3 && x >= 3)
printf("Test OK!\n");
else if (z <= 3 && y >= 3)
printf("Test OK!\n");
else
printf("Test failed!\n");
}
int main()
{
int x = 567;
printf("unit: %d\n", unit(x));
printf("tens: %d\n", tens(x));
return 0;
}