C ++ Help:数字总和可被n整除的数字

C ++ Help:数字总和可被n整除的数字

问题描述:

数字的总和可以被n整除的数字。



i真的不明白它应该如何工作,但是每个数字都应该用数字和那么这些数字的总和应该是否可被n整除。 (这只是猜测)



非常感谢任何帮助。

numbers whose sum of the digits is divisible by n.

i dont really understand how it`s supposed to work, but every number should be divided in digits and then the sum of those digits should be or not be divisible by n. (it is only a guess)

Any help is highly appreciated.

分为数字是非常简单:你需要的只是一个循环检查还剩下一个值,如果有,下一个数字就是基数的值模数,下一个数值变成当前值除以相同的基数(显然,这对整数最有效!)

Dividing into digits is pretty simple: all you need is a loop checking that there is still a value left, and if there is, the next digit is just the value modulus the base, and the next value becomes the current value divided by the same base (obviously, this works best with integers!)
digit = value % 10;
value /= 10;



然后你所要做的就是添加数字...



检查可分性更容易:x可以被x除以y模数y为零


Then all you have to do is add the digits...

Checking divisibility is even easier: x is divisible by y of x modulus y is zero