PTA——猜数字游戏

PTA

7-24 猜数字游戏 

 1 #include <stdio.h>
 2 int main()
 3 {
 4     int num, times;
 5     scanf("%d %d", &num,&times);
 6  
 7     int i = 0, guess;
 8     while(i< times){
 9         scanf("%d", &guess);
10         if(guess < 0){
11             printf("Game Over\n");
12             break;
13         } 
14         if(guess > num){
15             printf("Too big\n");
16         }
17         if(guess < num){
18             printf("Too small\n");
19         }
20         if(guess ==num){
21             if(i == 0){
22                 printf("Bingo!\n");
23             }else if(i < 3){
24                 printf("Lucky You!\n");
25             }
26             else{
27                 printf("Good Guess!\n");
28             }
29             break;
30         }
31         i++;
32     }
33     if(i>= times){
34         printf("Game Over\n");
35     }
36 }

 主要考察循环和判断

 

上一篇:4.17 小发现(dalao勿点)


下一篇:《如果》 ---Rudyard Kipling