-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram27.c
48 lines (39 loc) · 1.09 KB
/
program27.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
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int random_genNo=0,count=0,num;
int stime;
long ltime;
ltime = time(NULL);
stime = (unsigned) ltime/2;
srand(stime);
//generate random number
random_genNo=rand()%1000;
//run infinite loop
while(1)
{
//increase counter
count+=1;
//read number from user
printf("\n\nGuess a number from (0 to 1000): ");
scanf("%d",&num);
//compare entered number with generated number
if(random_genNo==num){
printf("Congratulations, you have guessed a correct number.");
break;
}
else if(random_genNo<num){
printf("Generated number is less than entered number, try your luck again...");
}
else if(random_genNo>num){
printf("Generated number is greater than entered number, try your luck again...");
}
if(count==7){
printf("\n\n### Maximum limit of atttempt finished, BAD LUCK !!!\n");
break;
}
}
return 0;
}