Delete element from array


#include <stdio.h>

int main()
{
   int arr[50], pos, c, n;

   printf("Enter number of elements in array\n");
   scanf("%d", &n);

   printf("Enter %d elements\n", n);

   for (c = 0; c < n; c++)
      scanf("%d", &arr[c]);

   printf("Enter the location where you wish to delete element\n");
   scanf("%d", &pos);

   if (pos >= n+1)
      printf("Deletion not possible.\n");
   else
   {
      for (c = pos - 1; c < n - 1; c++)
         arr[c] = arr[c+1];

      printf("Resultant array:\n");

      for (c = 0; c < n - 1; c++)
         printf("%d\n", arr[c]);
   }

   return 0;
}

OUTPUT :-



For Other Programs Visit The WebSite:-   https://www.techapurba.com/

Follow Me On Social Media :-




For tech related videos visit my other website :- https://apurbatechinfo.blogspot.com/

Post a Comment

0 Comments