title: qsort(): Sorting only even numbers of an array
body: <p>I'm trying to use the <code>qsort()</code> function in order to sort only the even numbers of an array (the odds remains in their positions).</p>
  
  <p>For instance if I have the array:</p>
  
  <pre><code>5 122 3 26 48
  </code></pre>
  
  <p>After sorting one would get:</p>
  
  <pre><code>5 26 3 48 122
  </code></pre>
  
  <p>My intuition was only to make a sort when both numbers pointed by <code>a</code> and <code>b</code> are even. </p>
  
  <p>This is my attempt:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int comp_even(const void *a, const void *b) {
      int l = *(int *)a;
      int r = *(int *)b;
  
      if ( !(l&amp;1) &amp;&amp; !(r&amp;1) ) //if both are even, then sort them in ascending order
          return (l-r);
  
      return 0;
  }
  
  int main() {
      int i, n;
      int a[1001];
  
      scanf("%d", &amp;n);
  
      for (i = 0; i &lt; n; i++) {
          scanf("%d", &amp;a[i]);
      }
  
      qsort(a, n, sizeof(int), comp_even);
  
      for (i = 0; i &lt; n; i++) {
          printf("%d ", a[i]);
      }
      return 0;
  }
  </code></pre>