c语言:随机猜数字游戏

来源:互联网 发布:mac视频字幕制作软件 编辑:程序博客网 时间:2024/06/06 02:23
    srand(time(NULL)); //用于重置随机函数    int a = rand() % 100;//随机一个数对100求余    int b = 0;//定义一个变量储存输入的值    int c = 0;//计数器    printf("请输入一个0-100的数字\n");    while (true)    {        scanf_s("%d", &b);//输入一个数字并储存        c++;//计数器        if (a > b)//对比        {            printf("你猜的数小了\n");        }        else if (a < b)//对比        {            printf("你猜的数大了\n");        }        else//对比        {            printf("恭喜你猜对了用次:%d次\n",c);//输出            return 0;        }    }
0 0
原创粉丝点击