/* Deletion in an array: Deleting an element from a desired position in an array. */
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of elements: ");
scanf("%d", &n);
int a[n], x, i;
for(i = 0; i < n; i++){
printf("Enter element %d: ", i+1);
scanf("%d", &a[i]);
}
printf("Array you entered is .....\n");
for(i = 0; i < n; i++)
printf("%d ", a[i]);
printf("\nEnter the position of the element you want to delete: ");
scanf("%d", &x);
for(i = 0; i < n; i++){
if(i == x-1)
continue;
printf("%d ", a[i]);
}
return 0;
}
Comments
Post a Comment