C语言玩猜字谜游戏

源码如下

#include<stdio.h>
#include <time.h>
#include <conio.h>   //rand()函数要使用的头文件
int main()
{
    
    
	srand((unsigned)time(NULL));     //指定了不同的种子,这样rand函数的结果就不完全相同了
	int number = rand() % 100 + 1;
	int a;
	int count = 0;
	do {
    
    
		printf("enter one number\n");
		scanf_s("%d", &a);
		if (a > number) {
    
    
			printf("please try again and your number too big\n");
		}
		else if (a < number) {
    
    
			printf("please try again and your number too low\n");
		}
		count++;    //计算自己猜了多少次
	} while (a != number);
		printf("you are a outstanding man!\n");
			printf("and u enter the number %d times/time \n", count);
	return 0;
}

补充:
100以内的猜字谜游戏,一般猜7次就可以猜到正确答案

猜你喜欢

转载自blog.csdn.net/qq_32100603/article/details/109268291