How does the modulus operator work?

Let’s say that I need to format the output of an array to display a fixed number of elements per line. How do I go about doing that using modulus operation? Using C++, the code below works for displaying 6 elements per line but I have no idea how and why it works? What if … Read more

Understanding The Modulus Operator %

(This explanation is only for positive numbers since it depends on the language otherwise) Definition The Modulus is the remainder of the euclidean division of one number by another. % is called the modulo operation. For instance, 9 divided by 4 equals 2 but it remains 1. Here, 9 / 4 = 2 and 9 % 4 = 1. In your example: 5 divided by 7 gives 0 but it … Read more