- L c语言猜数字游戏程序
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
#include<math.h>
void menu()
{
printf("***************************\n");
printf("********* 1.play \n");
printf(" 0.exit \n");
printf("****************\n");
}
void game()
{
int shu = 0;
int i = rand() % 200 + 1;
while (1)
{
printf(“请输入猜的数字\n”);
scanf_s("%d", &shu);
if (shu <i)
{
printf(“猜小了\n”);
}
else if (shu > i)
{
printf(“猜大了\n”);
}
else
{
printf(“猜对了\n”);
break;
}
};
}
int main()
{
int input = 0;
srand((unsigned)time(NULL));
do
{
menu();
printf(“是否开始游戏?1/0 >:”);
scanf_s("%d", &input);
switch (input)
{
case 1:
game();
break;
case 0:
break;
default:
printf(“选择错误!\n”);
break;
};
} while (input);
system(“pause”);
return 0;
}
新的学习,新的开始。
最新推荐文章于 2023-06-13 07:42:47 发布