我有这个代码,我打算创建一组 4 副套牌,问题是在花色中,在卡片 51 后,除法结果为 4,花色数组不返回初始位置,我怎么办解决这种情况?

谢谢

#include <stdio.h>
#define NCARTAS 52
int main()
{
    const char *numero[]= {"A","2","3","4","5","6","7","8","9","10","V","D","R"};
    const char *naipes[]= {"P","O","C","E"};
    char baralho[208];
    int posNumero,posNaipe;
    for(int i=0; i<208; i++)
    {
        baralho[i]=i;
        posNumero=i%13;
        posNaipe=i/13;

        printf("%s%s \n", numero[posNumero],naipes[posNaipe]);
    }
}

最佳答案

posNaipe = i % NCARTAS / 13;

会做的。这也是您了解运算符优先级和结合性知识的试金石。

关于c - 加入 4 副牌,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47435247/

10-11 21:21