-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
31 lines (24 loc) · 724 Bytes
/
main.c
File metadata and controls
31 lines (24 loc) · 724 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
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(){
int random,guess;
int no_of_guess=0;
srand(time(NULL));
random=rand() % 100 +1;
printf(" Welcome to the Number Guessing Game!\n");
printf("Try to guess the number between 1 and 100.\n");
do{
printf("\nEnter your guess number:");
scanf("%d",&guess);
no_of_guess++;
if(guess>random){
printf("\nGuess smaller number");
}else if(guess<random){
printf("\nGuess larger number");
}else{
printf("\nYour guess is right in %d attempts.\n",no_of_guess);
}
}while(guess!=random);
printf("\nThanks for playing the game\n");
}