#include <stdio.h>
#include <stdlib.h>
int main(void){
while(1){//無窮迴圈
int i=1;
int iNum,iRandom;
printf("Number:");
scanf("%d",&iNum);
do{
iRandom = (int)(rand()%10000);//這個部份做的不是非常精細,可以加入一些演算法
printf("%d %d\n",i,iRandom);//顯示出猜測的數字,會脫慢猜測的時間,可以刪除(或註解)
i++;
}while(iRandom != iNum);
printf("Time %d,The Number is %d\n",i,iRandom);
system("pause");
return 0;
}
Just Google it!!
[C語言](讓電腦)猜數字
2009/9/29
以下是猜數字(使用do...while)的範例,輸入一個數字(正數,整數),讓電腦以亂數(random)猜測
訂閱:
張貼留言 (Atom)
1 意見:
偉宗好厲害喔~~~不愧是我們的網管!!
張貼留言
歡迎在此留言,課堂上有不懂的地方也可以在這裡發問。