c语言小游戏200行代码
时间: 2023-10-17 14:22:16 浏览: 61
以下是一个简单的猜数字游戏,代码大约有200行左右:
```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int num, guess, tries = 0;
srand(time(0));
num = rand() % 100 + 1;
printf("I'm thinking of a number between 1 and 100. Can you guess what it is?\n");
do
{
printf("Enter your guess: ");
scanf("%d", &guess);
tries++;
if (guess > num)
{
printf("Too high! Try again.\n");
}
else if (guess < num)
{
printf("Too low! Try again.\n");
}
else
{
printf("Congratulations! You guessed the number in %d tries.\n", tries);
}
} while (guess != num);
return 0;
}
```
游戏规则很简单,程序随机生成一个1到100之间的整数,玩家需要通过输入猜测数字来猜出这个随机数,程序会根据猜测结果提示玩家是猜高了还是猜低了,直到猜中为止。游戏结束后,程序会输出猜测次数。