一道C语言猜数游戏编程题
发布网友
发布时间:2022-04-21 01:43
我来回答
共1个回答
热心网友
时间:2022-06-17 04:15
#include "stdio.h"
#include<time.h>
#include<stdlib.h>
void Guess(int magic, int guess)
{
static int c = 0;
c++;
if (magic == guess)
{
printf("\n你猜对了!\n你一共猜了%d次!", c);
exit(0);
}
if (magic < guess)
{
printf("\n太大了!\n");
}
else
{
printf("\n太小了!\n");
}
}
int main()
{
int m, n, i;
srand((int)time(0));
n=(rand() % 100) + 1;
//printf("n=%d\n",n);
for (i = 0; i < 10; i++) {
printf("请输入你猜测的数:");
scanf("%d", &m);
Guess(n, m);
}
return 0;
}