1/* 2 * Main. C 3 * C20-loop-20. guess the number game 4 * created on: August 18, 2014 5 * Author: the boomkeeper 6 ********** test section passed the *********** 7 */8 9 # include <stdio. h> 10 11 int main (void) {12 13 int random = 0, n = 0; // the random number entered by the system and the maximum number of guesses 14 int in = 0; // guess 15 int COUNT = 0 for each input; // count 16 17 scanf ("% I", & random, & N); 18 19 int I; 20 For (I = 0; I <n; I ++) {21 22 count ++; 23 24 scanf ("% d", & in ); 25 26 if (in <0) {27 printf ("% s \ n", "Game over"); 28} Else if (in! = Random) {29 If (in> random) 30 printf ("% s \ n", "too big"); 31 if (in <random) 32 printf ("% s \ n", "Too small"); 33} else if (in = random) {34 break; 35} 36} 37 38 If (COUNT = 1) {39 printf ("% s \ n", "Bingo! "); 40 return 0; 41} else if (count <= 3) {42 printf (" % s \ n "," Lucky you! "); 43 return 0; 44} else if (count <= N) {45 printf (" % s \ n "," Good guess! "); 46 Return 0; 47} 48 49 return 0; 50}
Question link:
Http://pat.zju.edu.cn/contests/basic-programming/%E5%BE%AA%E7%8E%AF-20
.