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();}下如為執行結果
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();}下如為執行結果