淘先锋技术网

首页 1 2 3 4 5 6 7

c语言之猜数游戏?

1 写入所需头文件#include <stdlib.h>/*随机函数的申明*/#include <stdio.h> #include <time.h>

2所需变量的定义 main(){int n,g,c=100,d=0,t;

srand( (unsigned)time( NULL ) );n=rand()%100; /*产生并调用随机数*/

3 程序其他部分printf("please input the number you guess between 0 to 100\t");scanf("%d",&g);while(g!=n){if(g<n) { d=g; printf("That was small,\n please guess it again and input a number between %d to %d\n",d,c);

scanf("%d",&t);g=t;}if(g>n) {c=g; printf("That was large,\n please guess it again \ and input a number between %d to %d\n",d,c) ; scanf("%d",&t);g=t;} }if(g==n)printf("\t\t\t|----------|\n\t\t\t|you got it|\n\t\t\t|----------|\n");printf("\n\t\t\t Game over\n");getch();}下如为运行结果

again函数java,c语言之猜数游戏