将X除以Y,返回最后一个项目,部分设置

Cap*_*chi -2 c# math

我可能错过了一些非常简单的东西,但是我想弄清楚如何计算在将X除以Y之后剩下的东西.我不是指余数,我的意思是,例如,如果我将100除以7 => 6组15 +一组10,我怎么得到10?

我没有要显示的代码,因为我不知道从哪里开始.X和Y都是整数.

Mat*_*son 5

它并不像使用模数那么简单.这个小巧的位是根据组数计算你的初始组大小.

试试这个:

int population = 100;
int numberOfGroups = 7;
int groupSize = (population + numberOfGroups - 1)/numberOfGroups;

Console.WriteLine(groupSize);

int remainder = population%groupSize;

Console.WriteLine(remainder);
Run Code Online (Sandbox Code Playgroud)