我先寫個C語言版原始碼
PHP 語法:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main(){
int rndNum, gNum, rangeMax = 100, rangeMin = 0;
srand(time(NULL));
rndNum = rand() % 99 + 1;
printf("++++猜數字遊戲++++\n\n");
do{
printf("請輸入 %d ~ %d 之間的數字:", rangeMin, rangeMax);
scanf("%d", &gNum);
if(gNum >= rangeMax || gNum <= rangeMin) printf("+++++超出範圍!+++++\n");
else if(gNum > rndNum) rangeMax = gNum;
else if(gNum < rndNum) rangeMin = gNum;
}while(gNum != rndNum);
printf("++++++答對了!++++++\n");
}