title: Why is the behavior of the modulo operator (%) different between C and Ruby for negative integers?
body: <p>I was running some code in <a href="http://tryruby.org/" rel="nofollow">here</a>. I tried <code>-40 % 3</code>. It gives me the output <code>2</code>. when I performed the same operation in C, I get:</p>
  
  <pre><code>int i = (-40) % 3
  printf("%d", i);
  </code></pre>
  
  <p>output is   </p>
  
  <pre><code>-1
  </code></pre>
  
  <p>How are both languages performing the modulo operation internally?</p>