代碼
//c語言猜100以內(nèi)的數(shù) 游戲
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
srand(time(0));
int num = rand()%100 + 1;
int count = 0;
int yourNum = 0;
printf("計算機已經(jīng)想好了100以內(nèi)的正整數(shù)\n請猜: ");
do{
scanf("%d",&yourNum);
count ++;
if(yourNum > num)
{
printf("哈哈,猜大啦! 繼續(xù)猜: ");
}
else if(yourNum < num)
{
printf("哈哈祖灰,猜小啦! 繼續(xù)猜: ");
}
}while(yourNum != num);
printf("你猜了%d次就猜對啦钟沛!\n",count);
return 0;
}