1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <stdio.h> #include <time.h> #include <stdlib.h> #include <string.h> main () { int data,count,goal; while( 1 ) { srand(time(0)); goal=rand() %100; count=0; printf ("欢迎进入猜数游戏!"); printf("请输入你猜的数字!\n"); scanf("%d",&data); while(data!=goal) { if (data>goal) { printf("您猜的数有些大,请耐心重输入!\n"); count++; } else { printf("您猜的数有些小,请耐心重输入!\n"); count++; } scanf("%d",&data); } printf("真聪明,祝贺!"); printf("您猜的次数: %d\n",count); } }
|