forked from avinashbest/codewithharry-c-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26_Project_1.c
More file actions
33 lines (30 loc) · 766 Bytes
/
26_Project_1.c
File metadata and controls
33 lines (30 loc) · 766 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//A simple C Program game to guess the number.
int main()
{
int number, guess, n_guess_attemps = 1;
srand(time(0));
number = rand() % 10 + 1; //Genrate a random number b/w 1 to 10
// printf("\nThe number is %d.\n", number);
do
{
printf("\nGuess the number b/w 1 to 10: ");
scanf("%d", &guess);
if (guess > number)
{
printf("Lower number please!\n");
}
else if (guess < number)
{
printf("Higher number please!\n");
}
else
{
printf("You guessed it in %d attempts\n", n_guess_attemps);
}
n_guess_attemps++;
} while (guess != number);
return 0;
}