title: Count the number of duplicate elements in an array - C
body: <p>Take a input from user in an Array of a size N and print the total number of duplicate elements (The elements which occur two or more times).</p>
  <p>Input Format: The first line contains N. The second line contains the N positive integer separated by a space.</p>
  <p>Output Format: Count of duplicate elements.</p>
  <p>The program I wrote works for only two same elements and fails to read more than 2 duplicates.</p>
  <pre><code>#include&lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      int arr[1000],i,j,n,count=0;
      scanf(&quot;%d&quot;,&amp;n);
  
      for(i=0;i&lt;n;i++)
      {
          scanf(&quot;%d&quot;,&amp;arr[i]);
      }
  
      for(i=0;i&lt;n;i++)
      {
          for(j=i+1;j&lt;n;j++)
          {
              if(arr[i]==arr[j])
              {
                  count=count+1;
                  break;
              }
          }
      }
      printf(&quot;%d&quot;,count);
  
  }
  </code></pre>
  <p>Input (for an eight-digit example):</p>
  <pre><code>1 2 3 1 2 1 5 6
  </code></pre>
  <p>Incorrect output of this code:</p>
  <pre><code>3
  </code></pre>
  <p>The expected output is 2, the count of elements which has duplicates (1 has two duplicates and 2 has one duplicate).</p>
  <p>So please explain what am doing wrong?</p>