-
Notifications
You must be signed in to change notification settings - Fork 0
/
num
47 lines (46 loc) · 1.02 KB
/
num
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
#include <stdio.h>
#include <stdlib.h>
void main() {
int chislo = 0, x = 0, otvet = -1, high = 1000, low = 0, pop = 0;
char znak = NULL;
printf("Select mode:\n1-You guess the number\n2-Program guesses the number\n");
scanf("%d", &x);
switch (x) {
case 1:
srand(time(NULL));
chislo = (rand() % 999) + 1;
printf("Enter the number:\n");
while (chislo != otvet) {
scanf("%d", &otvet);
if (chislo > otvet)
printf("The hidden number is greater\n");
else if (chislo < otvet)
printf("The hidden number is less\n");
pop++;
}
printf("You guessed!\n");
printf("Count of attempts: %d", pop);
break;
case 2:
printf("Enter the hidden number:\n");
scanf("%d", &chislo);
while (znak != '=') {
otvet = (high + low) / 2;
printf("%d ?\n", otvet);
getchar();
znak = getchar();
switch (znak) {
case '<':
high = otvet;
break;
case '>':
low = otvet;
break;
}
pop++;
}
printf("The number is guessed: %d\n", otvet);
printf("Count of attempts: %d", pop);
break;
}
}