/* * modrand1.c */ #include #include #include #define MAX 10 int main(void) { int num, guess; int count = 0; system("clear"); printf("You are to guess a number "); printf("between 0 and %d.\n", MAX-1 ); srand( time(NULL) ); num = rand()%MAX; do { count=count+1; printf("Guess what number I have: "); scanf("%d", &guess); if (guess == num) { printf("Exactly!"); break; } else if (guess < num) printf("%d is smaller than answer\t", guess); else printf("%d is greater than answer\t", guess); printf("Try one more time!\n"); } while(1); printf("You got the right answer in %d guesses.\n", count); return 0; }