c语言猜数字游戏了解一下

  今天要来写的是一个猜数字游戏的小代码,猜数字游戏虽然简单,但它其实包含了很多东西。对于初学者来说是一件挺有趣的尝试。在学完了分支结构和选择语句时,建议大家可以自己试一试。

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void menu()
{
printf(“\n");
printf(“1.我想玩**\n”);
printf(“0.不想玩**\n”);
printf("
\n”);
}
void game()
{
int input = rand()%100+1;
int num = 0;
printf(“请输入一个数”);
while(1)
{
scanf("%d",&num);

	 if(num == input)
	 {	 
	      printf("猜对了\n");
		  break;
     }
	 else if(num > input)
	 {
	 	 printf("猜大了\n");
	 } 
    else(num < input);
     {
	      printf("猜小了\n");
     }
 }

}

猜你喜欢

转载自blog.csdn.net/qq_43232778/article/details/82904011
今日推荐