title: intersection and union of two unsorted arrays
body: <p>This code is meant to find intersection and union of two unsorted arrays which may contain duplicates.</p>
  
  <p>The union works fine, but when trying to access intersection array memory, I get garbage results.</p>
  
  <p>I can't find out where the problem is, tried to debug it but it didn't help me much either.</p>
  
  <p>note: <code>remember[]</code> is an array of flags that saves indices of intersection elements in two arrays.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
      int i,n1,n2,j;
      int user1[20];
      int unionSize;
      int intersectionArraySize;
      printf("enter array1 size::\n");
      scanf("%d",&amp;n1);
      printf("array1: ");
      for(i=0; i&lt;n1; i++)
      {
          scanf("%d",&amp;user1[i]);
          if (i&gt;0) if(user1[i]==user1[i-1])  user1[i-1]=user1[i];
  
      }
      int user2[20];
      printf("enter array2 size::\n");
      scanf("%d",&amp;n2);
      for(i=0; i&lt;n2; i++)
      {
          scanf("%d",&amp;user2[i]);
          if (i&gt;0) if(user2[i]==user2[i-1])  user2[i-1]=user2[i];
  
  
      }
  
      int unionArray[20];
      int remember[20]= {0}; // save index of common elements btn 2 arrays
      int intersectionArray[20]={0};
      intersectionArraySize=0;
      unionSize=n1;
      int index=0;
  
      for(i=0; i&lt;n1; i++)
      {
          for(j=0; j&lt;n2; j++)
          {
              if (user1[i]==user2[j])
              {
                  remember[j]=1;
                  intersectionArray[index]==user1[i];
                  intersectionArraySize++;
                  index++;
              }
              else unionArray[i]=user1[i];
          }
  
      }
      for(i=0; i&lt;n2; i++)
      {
          if(remember[i]!=1)
          {
              unionArray[n1]=user2[i];
              n1++;
              unionSize++;
          }
      }
  
      printf("Union: ");
      for (i=0; i&lt;unionSize; i++)
      {
          if(i==unionSize-1) printf("%d\n",unionArray[i]);
          else printf("%d ,",unionArray[i]);
      }
      printf("intersection: ");
      for (i=0; i&lt;intersectionArraySize; i++)
      {
          if(i==intersectionArraySize-1) printf("%d\n",intersectionArray[i]);
          else printf("%d ,",intersectionArray[i]);
      }
      return 0;
  }
  </code></pre>