# 完成猜数字游戏 //C语言 猜数字游戏（编写过程详解）

	int i, j, k;
int num = 0;

/*生成随机数字*/
num = rand();
printf("%d\n", num);

void play(int x)
{
printf("%d\n", x);
printf("开始游戏");
}
scanf("%d", &k);

switch (k)
{
case 1:
play(num);

case 2:
break;
}

void play(int x)
{
printf("%d\n", x);
printf("开始游戏");

printf("游戏结束");
}
int main()
{
int i, j, k;
int num = 0;

/*生成随机数字*/
num = rand();
printf("%d\n", num);

again:
{
scanf("%d", &k);
switch (k)
{
case 1:
play(num);
goto again;
case 2:
break;
}
}



void play(int x)
{
int number=0;
printf("请输入数字\n");

again_1:
{
scanf("%d", &number);
while (number != x)
{
if (number > x)
{
printf("Big"); goto again_1;
}
else
{
printf("Small"); goto again_1;
}

}printf("Right\n请选择\n\n");
}
}

/*
***猜数字游戏
*/

void play(int x)
{
int number=0;
printf("请输入数字\n");

again_1:
{
scanf("%d", &number);
while (number != x)
{
if (number > x)
{
printf("Big"); goto again_1;
}
else
{
printf("Small"); goto again_1;
}

}printf("Right\n请选择\n\n");
}
}

int main()
{
int i, j, k;
int num = 0;

/*生成随机数字*/
num = rand();

again:
{
printf("开始游戏\n1.开始\n2.退出\n");
scanf("%d", &k);
switch (k)
{
case 1:
play(num);
goto again;
case 2:
break;
}
}

system("pause");
return 0;
}

	/*生成随机数字*/
//num = rand();
srand(time(NULL));
num = rand() % 100

#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/*
***猜数字游戏
*/

void play(int x)
{
int number=0;
printf("请输入数字\n");

again_1:
{
scanf("%d", &number);
while (number != x)
{
if (number > x)
{
printf("Big\n"); goto again_1;
}
else
{
printf("Small\n"); goto again_1;
}

}printf("\n***Right***\n *********\n   ******\n   ****\n    **\n");
}
}

int main()
{
int k;
int num = 0;

/*生成随机数字*/
//num = rand();
srand(time(NULL));
num = rand() % 100;

again:
{
printf("开始游戏\n1.开始\n2.退出\n");
scanf("%d", &k);
switch (k)
{
case 1:
play(num);
goto again;
case 2:
break;
}
}

system("pause");
return 0;
}



https://mp.csdn.net/postedit/79788815