1
#include <stdio.h>
2
int guessnum(int,int);
3
char correntchar(void);
4
int main(void)
5

{
6
char ch;
7
int min=1;int max=100;
8
int value;
9
printf("Pick a integer form 1 to 100,then I will try to guess it:");
10
printf("\nSome answers you can choose to help me,as follows:");
11
printf("\nb bigger than my answer s smaller");
12
printf("\ny corrent.");
13
value=guessnum(min,max);
14
printf("\nIs it %d?",value);
15
16
while((ch=correntchar())!='y')
17
{
18
//while(getchar())
19
if(ch=='b')
20
min=value;
21
else if(ch=='s')
22
max=value;
23
value=guessnum(min,max);
24
printf("\nIs it %d?",value);
25
}
26
printf("Oh,year!");
27
return 0;
28
}
29
int guessnum(int min,int max)
30

{
31
return (max+min)/2;
32
}
33
char correntchar()
34

{
35
char ch;
36
ch=getchar();
37
while(getchar()!='\n')
38
continue;
39
return ch;
40
}

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
