设计一个简单的猜数游戏:先由计算机“想”一个数请用户猜,如果用户猜对了,则计算机给出提示信息“Right”,否则提示“Wrong”,并告诉用户是大还是小。
2 回答
a2596446032
TA贡献1条经验 获得超0个赞
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
srand((unsigned)time(NULL));
int number=rand();
int guessNumber;
do
{
printf("Your number is ");
scanf("%d",&guessNumber);
if(number!=guessNumber)
{
printf("Wrong\n");
if(guessNumber>number)
{
printf("Bigger than my number\n");
}
else if(guessNumber<number)
{
printf("Less than my number\n");
}
}
else
{
printf("Right");
}
} while (number!=guessNumber);
system("pause");
return 0;
}
- 2 回答
- 1 关注
- 1164 浏览
添加回答
举报
0/150
提交
取消