首页 > 代码库 > *循环-20. 猜数字游戏

*循环-20. 猜数字游戏

 1 /* 2  * Main.c 3  * C20-循环-20. 猜数字游戏 4  *  Created on: 2014年8月18日 5  *      Author: Boomkeeper 6  *********测试部分通过********* 7  */ 8  9 #include <stdio.h>10 11 int main(void){12 13     int random = 0,N = 0;//系统输入的随机数和最大猜测次数14     int in = 0;//每次输入的猜测15     int count = 0;//计次16 17     scanf("%i %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 }

 

 

题目链接:

http://pat.zju.edu.cn/contests/basic-programming/%E5%BE%AA%E7%8E%AF-20

 

 

.