I am trying to delete a number from an array at a given position.
IN MY CODE: 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. but I am getting 3 6 2 2 4 any help?
MY CODE:
#include<stdio.h>
int main(void){
int n;
int i;
int position;
int a[10];
printf("Enter how many numbers\n");
scanf("%d",&n);
printf("Enter the numbers\n");
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
printf("Enter the position of the number you want to delete\n");
scanf("%d",&position);
for(i=0;i<n;i++){
while(i == position){
a[i] = a[i+1];
i = i+1;
}
}
printf("Elements after:\n");
for(i=0;i<n;i++){
printf("%d ",a[i]);
}
return 0;
}
