title: Division and Mod with negative numbers
body: <p>I'm trying to solve a <a href="http://www.urionlinejudge.com.br/repository/UOJ_1837_en.html" rel="nofollow">contest problem</a> that was supposed to be simple.</p>
  
  <p>What is the result of the quotient <strong>q</strong> and remainder <strong>r</strong> for 2 numbers <strong>a</strong> and <strong>b</strong> (-1.000 ≤ a, b &lt; 1.000)?</p>
  
  <p>The input consist of 2 numbers <strong>a</strong> and <strong>b</strong>.</p>
  
  <p>Example of 3 different inputs:<br>
  7 3<br>
  7 -3<br>
  -7 3   </p>
  
  <p>The output is the quotient <strong>q</strong> followed by the remainder <strong>r</strong> of the division of <strong>a</strong> by <strong>b</strong>.</p>
  
  <p>Example of output:<br>
  2 1<br>
  -2 1<br>
  -3 2   </p>
  
  <p>My code :</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main(){
      int a,b;
      scanf("%d %d",&amp;a,&amp;b);
  
      int r = 0;
      if(a &gt; 0)
          r = a%b;
      if(a &lt; 0)
          r = (a%b + b)%b;
  
  
      printf("%d %d\n",(a-r)/b,r);
  }
  </code></pre>
  
  <p>My solution is wrong in 10% of the test cases and i don't know what is wrong.</p>