title: How does the modulus operator work?
body: <p>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?</p>
  
  <p>Using C++, the code below works for displaying 6 elements per line but I have no idea how and why it works?</p>
  
  <pre><code>for ( count = 0 ; count &lt; size ; count++)
  {
      cout &lt;&lt; somearray[count];
      if( count % 6 == 5) cout &lt;&lt; endl;
  }
  </code></pre>
  
  <p>What if I want to display 5 elements per line? How do i find the exact expression needed?</p>