shallow0329 2023-07-19 20:00 采纳率: 0%
浏览 45

关于#c语言#的问题:答案下:请问其中的s为什么不是30-s,30-s才是剩余数的个数啊#include <time.h>

两方分别报数 谁先报到30获胜计算机报数原则:若剩下的数除以3余1,报一个数,若余2则报两个数,否则随机报一或两个数。答案下:请问其中的s为什么不是30-s,30-s才是剩余数的个数啊

</>#include<time.h>#include<stdio.h>#include<stdlib.h>int Input(int t);int ControlComputer(int s);int Rnd();
 int main(){    int tol = 1;    
if (Rnd() == 1)    {        tol = Input(tol);    }    while (tol < 30)    {        
tol = ControlComputer(tol);        
    if (tol == 30)        {        
    printf("Player lose\n");        }    
    else        {            tol = Input(tol);            if (tol >= 30)        
    {                printf("Computer lose\n");            }        }    }    
printf("Game Over");    
return 0;}
int Input(int t){    
int a;    
do {        printf("please count\n");    
    scanf("%d", &a);        
     if (a > 2 || a < 1) {            printf("Error input\n");        }        
    else        {            printf("you count is %d\n", t + a);        }    } while (a > 2 || a < 1);    
return t + a;}
int ControlComputer(int s){    
int c;    
printf("computer count\n");
    if (s % 3 == 1)    {        s++;                printf("%d\n", s);    }
    else if (s % 3 == 2)    {        s += 2;                printf("%d\n", s);    }    
else    {        c = Rnd() + 1;        s += c;                printf("%d\n", s);    }    
   return s;}
int Rnd(){    srand(time(NULL));    
return rand() % 2;}</>
  • 写回答

2条回答 默认 最新

  • 爱编程的小芒果 2023-07-19 20:08
    关注

    你的程序可以稍微整理下吗,把题目发我,我试试看

    评论

报告相同问题?

问题事件

  • 创建了问题 7月19日

悬赏问题

  • ¥15 HTML5的section文字占地问题
  • ¥15 这个结构体为什么会出错呢?
  • ¥15 ROH绘图及近交系数的计算
  • ¥15 手动下载基因拼接数据库的渠道
  • ¥30 微机原理相关问题,求解
  • ¥15 多种类数据输入的语义分割模型方法有吗
  • ¥15 cesium二维地图绘制实体rectangle颜色问题
  • ¥15 网络分析仪面板参数解释
  • ¥15 车载image sensor的 datasheet
  • ¥15 kotlin multiplaform 的共享模块支持蓝牙吗还是说安卓和ios的蓝牙都要自己配