|
发表于 2018-5-25 13:38:33
|
显示全部楼层
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main(void)
- {
- int a,count = 0, i, j, n;
- for (j = 0; j < 10; j++)
- {
- i = rand() % 100;
- printf("pleas guess numbers : \n");
- while ( n = scanf("%d", &a))
- {
- if (a < i)
- {
- printf("too low\n");
- count++;
- }
- if (a > i)
- {
- printf("too high\n");
- count++;
- }
- if (count > 9)
- {
- printf("\n猜测超过十次,请猜下一个数: \n");
- count = 0;
- break;
- }
- }
- if (a == i)
- {
- printf("一共猜测%d次正确\n", ++count);
- break;
- }
- else if (!n) {
- printf("Enter error\n");
- break;
- }
- else
- ;
- }
- printf("\n");
- system("pause");
- return 0;
- }
复制代码 |
|