title: Deleting a number from an array
body: <p>I am trying to delete a number from an array at a given position.</p>
  <p>IN MY CODE: <strong>the array has 5 numbers, 3 6 5 2 4 . I want to delete the number at position 2 which is 5. The output after deleting should be 3 6 2 4.</strong> <strong>but I am getting 3 6 2 2 4</strong> any help?</p>
  <p><strong>MY CODE:</strong></p>
  <pre><code>#include&lt;stdio.h&gt;
  int main(void){
    int n;
    int i;
    int position;
    int a[10];
    printf(&quot;Enter how many numbers\n&quot;);
    scanf(&quot;%d&quot;,&amp;n);
    printf(&quot;Enter the numbers\n&quot;);
    for(i=0;i&lt;n;i++){
      scanf(&quot;%d&quot;,&amp;a[i]);
    }
    printf(&quot;Enter the position of the number you want to delete\n&quot;);
    scanf(&quot;%d&quot;,&amp;position);
  
    for(i=0;i&lt;n;i++){
      while(i == position){
        a[i] = a[i+1];
        i = i+1;
      }
    }
    printf(&quot;Elements after:\n&quot;);
    for(i=0;i&lt;n;i++){
      printf(&quot;%d &quot;,a[i]);
    }
    return 0;
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/5OFlT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5OFlT.png" alt="OUTPUT" /></a></p>