title: Deleting entries from arrays
body: <p>I wrote a program to delete a certain element from an array but it doesn't seem to work as I intended and I can't spot the error here. I'm aware it is kind of a simple issue but I would like to know why the output is as such.</p>
  
  <p>Here is the code itself:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main(void)
  {
      int numList[30], sizeofArray, deleteElement, i, j, k, a, b;
      printf("Please specify the number of entries: ");
      scanf_s("%d", &amp;sizeofArray);
  
      printf("\nPlease initialize the list with %d entries: ",sizeofArray);
      for (i = 0; i &lt; sizeofArray; i++)
          scanf_s("%d", &amp;numList[i]);
      printf("\nInitial values in the array are: ");
      for (j = 0; j &lt; sizeofArray; j++)
          printf("%d ", numList[j]);
  
      printf("\nPlease specify the element you want to delete: ");
      scanf_s("%d", &amp;deleteElement);
      for (k = 0; k &lt; sizeofArray; k++) {
          if (deleteElement == numList[k]) {
              for (a = k; a &lt; sizeofArray - 1; a++);
                  numList[a] = numList[a+1];
              k--;
              sizeofArray--;
          }
      }
      printf("\nThe updated list contains the elements: ");
      for (b = 0; b &lt; sizeofArray; b++)
          printf("%d ", numList[b]);
  }
  </code></pre>
  
  <p>And the output is:</p>
  
  <p>Please specify the number of entries: 6</p>
  
  <p>Please initialize the list with 6 entries: 20 9 4 9 9 33</p>
  
  <p>Initial values in the array are: 20 9 4 9 9 33</p>
  
  <p>Please specify the element you want to delete: 9</p>
  
  <p>The updated list contains the elements: 20</p>