title: Deleting an array element in C
body: <p>I wrote the following program to delete an array element entered by the user.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;conio.h&gt;
  
  void main() {
      int j, i, a[100], n, key, l;
      clrscr();
      printf("Enter the number of elements:");
      scanf("%d", &amp;n);
      printf("\nEnter the elements:\n");
      for (i = 0; i &lt; n; i++)
          scanf("%d", &amp;a[i]);
      printf("\nEnter the element to delete:");
      scanf("%d", &amp;key);
      l = n;  //Length of the array
      for (i = 0; i &lt; l; i++) {
          if (a[i] == key) {
             for (j = i; j &lt; l; j++)
                 a[j] = a[j + 1];
             l--;    //Decreasing the length of the array
          }
      }
  
      printf("\nThe new array is \n");
      for (i = 0; i &lt; l; i++)
          printf("%d ", a[i]);
       getch();
  }
  </code></pre>
  
  <p>It works fine for most inputs but when the input is something like: <code>1 2 2 3 5</code> (here <code>2</code> repeats consecutively) and the element to be deleted is <code>2</code>, the output is <code>1 2 3 5</code>.</p>
  
  <p>How can I modify the program such that all instances of the entered element is removed?</p>