If you want to get multiples of a number, use the modulus operator %
. The modulus operator is used to get the remainder of a division. For example, 4 % 3 = 1
, 5 % 3 = 2
.
Thus, to get multiples of n
, we select only numbers whose remainders are 0 when dividing them by n
. The code above shows how it works.