Game in c-guess numbers
Program writing: use c to create a random number between 0 and, and follow the prompts to guess the correct number. # Include <stdio. h> # include <stdlib. h> # include <time. h> void menu () {printf ("\ n"); printf ("*********** 1. start the game ************** \ n "); printf (" ************* 0. exit the game *************** \ n "); printf (" \ n ");} int main () {int num = 1; printf ("welcome to the guess number GAME \ n"); while (num) {menu (); printf ("select :"); scanf ("% d", & num); // enter 0 or 1, select 0 and 1 switch (num) {case 1: {int n = 0; int ch = 0; srand (unsigned int) time (NULL); // an unsigned integer random number is generated based on time n = rand () % 101; // generate a random number between 0 and 100 while (1) {printf ("Please guess the number between 0 and \ n"); scanf ("% d ", & ch); // input the size of the guessed number. if (ch> n) {printf ("You guessed it \ n");} else if (ch <n) {printf ("You guessed it \ n");} else {printf ("Congratulations, you guessed it \ n"); break ;}} break;} default: printf ("game exit \ n"); break;} return 0;} run the following results: you are welcome to use the guess digital game *********** 1. start the game ************************** 0. exit the game **************** select: 1, Please guess one (0-100) number 45. if you guess it is too big, Please guess one (0-100) number 35. if you guess it is too small, Please guess one (0-100) when you guess about 40, Please guess one (0-100). Congratulations, you guessed it. *********** 1. start the game ************************** 0. exit the game *************** select: 0 game exit Press any key to continue