From fdf211c06f67419ba14111c49925bc68863518f3 Mon Sep 17 00:00:00 2001 From: pj8a4cfvw <1626433731@qq.com> Date: Fri, 20 Oct 2023 09:54:19 +0800 Subject: [PATCH] ADD file via upload --- 00.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 00.c diff --git a/00.c b/00.c new file mode 100644 index 0000000..089cb2f --- /dev/null +++ b/00.c @@ -0,0 +1,63 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include + +void test01() +{ + int num = 0; + while (num < 10) + { + printf("num=%d\n", num); + num++; + } + + +} + +//猜数字 +void test02() +{ + //设置随机数的种子 + srand((unsigned int)time(NULL));//固定代码,必须记 + //int i = 0; + //while (i < 10) + //{ + // int num=rand() % 100 + 1;//rand()会生成随机数rand对100取余会生成0-99的随机数,再加1就成0-100 + // printf("%d\n",num); + // i++; + //} + int num = rand() % 1000 + 1; + int val = 0; + + printf("请您输入一个1000以内的正整数\n"); + while (1) //()中的1为真,所以会一直循坏 + { + + scanf("%d", &val); + + if (val > num) + { + printf("输入大了\n"); + } + else if (val < num) + { + printf("输入小了\n"); + + } + else + { + printf("恭喜您,猜对了!\n"); + break; + } + + } +} + +int main() +{ + test02(); + + system("pause"); + + return 0; +} \ No newline at end of file