小编Tex*_*Qas的帖子

模数运算符如何工作?

假设我需要格式化数组的输出以在每行显示固定数量的元素.我如何使用模数运算来做到这一点?

使用C++,下面的代码适用于每行显示6个元素,但我不知道它是如何工作的?

for ( count = 0 ; count < size ; count++)
{
    cout << somearray[count];
    if( count % 6 == 5) cout << endl;
}
Run Code Online (Sandbox Code Playgroud)

如果我想每行显示5个元素怎么办?我如何找到所需的确切表达式?

c++ modulus

30
推荐指数
3
解决办法
27万
查看次数

标签 统计

c++ ×1

modulus ×1