title: A program that counts unique elements in an un-ordered array
body: <pre><code>int num_distinct(int a[], int n)
  {
    int i, k, j, count=0;
    int max = a[0];
  
    for (i = 1; i &lt; n; i++) {
      if (max &lt; a[i]) {
        max = a[i];
      }
    }
    for (k = 0; k &lt; n; ++k) {
      for (j = 0; j &lt; n; ++j) {
        if (a[j] == max) {
          ++count;
          --max;
          break;
        }
      }
    }
    return (count);
  }
  </code></pre>
  
  <p>What i tried to do is find the max in the array and compare that to the rest of the elements in the array. It works, but when the array skips a number i.e. (1,2,2,5,6,7,8) &lt;-- it skipped 3 and 4. My code will only count 8,7,6,5 which returns 4 unique numbers.</p>