#include <stdio.h> #include <Windows.h> #include <stdlib.h> #include < stdio.h> #include <Windows.h> #include <stdlib.h> #include <time.h>void Output () {printf ("********************* Welcome to play guessing number game ***********************\n");p rintf ("********************* input 1 into the Guess number game ***********************\n");p rintf ("********************* Enter 0 Exit guess number game ***********************\n ");} Int main () {int charge = 1;while (charge) {output ();p rintf ("Please select;:"); scanf ("%d", &charge ); switch (charge) {Case 1:{int value = 0,input = 0;srand ( (unsigned int) Time ( NULL ) ); Value = rand ()%101;while (1) {printf ("Please enter the number you guessed:"); scanf ("%d", &input); if (input<value) {printf ("Your answer is small");} Else if (input>value) {printf ("you answered Big");} else {printf ("Congratulations on your correct answer \ n"); }break; }default:{printf ("Game over \"); System ("Pause"); return 0;}
1, the appeal is the code realization, the operation result;
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/75/7C/wKiom1Y6BwPyFNycAAAeW3Zc-xw940.gif "title=" gs.gif "alt=" Wkiom1y6bwpyfnycaaaew3zc-xw940.gif "/>
2, thinking analysis;
(1) is to find a way to get a number, and each time the value of the different;
WORKAROUND: The rand () function can produce a random number, but requires a seed
Srand ((unsigned int) time (NULL)) The seed of the//rand () function
(2) with the random value of the first step, the guessing number game is achieved by comparing the numbers you enter.
(3) In order to always be able to play the game, so put in a while loop to exit the game through the flag flag.
3, Summary: To do each program to achieve practical problems, thinking and logic must be clear, first thought and logic to write code again.
The first C language implementation of the Guess number game