-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuessingGame.c
37 lines (32 loc) · 875 Bytes
/
GuessingGame.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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int num, guess, count = 0;
srand(time(0));
num = rand() % 50 + 1;
printf("Your guess is : \n");
scanf("%d", &guess);
while (num != guess)
{
if (num > guess)
{
printf("The number guessed by you is smaller than the answer, go little high\n");
count++;
printf("Your guess is : ");
scanf("%d", &guess);
}
else if (num < guess)
{
printf("The number guessed by you is larger than the answer, go little low\n");
count++;
printf("Your guess is : ");
scanf("%d", &guess);
}
}
printf("The number guessed by you is absolutely correct\n");
count++;
printf("The number of trials taken by you is %d\n", count);
return 0;
}