#include<stdio.h> #include<stdlib.h> #include<math.h> #include<time.h> int main() { int i,j,c,g=1; while(g)/*利用g来判断是否继续进行游戏*/ { srand((unsigned)time(NULL)); i=rand()%100;/*随机生成整数*/ c=0;/*比较次数置零*/ for(;;) { printf("Please input the data请输入数据:"); scanf("%d",&j); c++;/*次数累加*/ if(j>i) printf("Too high太大了!\n"); else if(j<i) printf("Too low太小了!\n"); else { printf("Right正确!\n"); printf("The c is:%d\n",c); printf("Wanna continue想继续吗? 1.continue继续 0.exit退出\n"); scanf("%d",&g);/*选择是否继续*/ break; } } } } |
|