猜数游戏
2015-05-06 03:52:13 -0400
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
int x,y;
int k=0;
srand((unsigned)time(0));
x=rand()%100+1;
while(1)
{
printf("请输入您所猜的数据:");
scanf("%d",&y);
k++;
if(x==y)
{
printf("您已猜了%d次,恭喜您这次猜对了\n",k);
break;
}
else
{
if(x>y)
printf("您已猜了%d次,您输入的数据小了\n",k);
else
printf("您已猜了%d次,您输入的数据大了\n",k);
}
}
}
Back to home
Subscribe |
Register |
Login
| N