• Write a c program to insert and delete an element in array
  • Write a c program to delete an element in an array
  • C Program to Delete the Specified Integer from an Array without using function



Program #1: Write a c program to insert and delete an element in array


  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6.   
  7.      int array[10];
  8.  
  9.     int i, n, position, element, exist = 0;
  10.  
  11.  
  12.     printf("Enter number of elements \n");
  13.  
  14.     scanf("%d", &n);
  15.  
  16.     printf("Enter the elements\n");
  17.  
  18.     for (i = 0; i < n; i++)
  19.  
  20.     {
  21.  
  22.         scanf("%d", &array[i]);
  23.  
  24.     }
  25.  
  26.     printf("Input array elements are\n");
  27.  
  28.     for (i = 0; i < n; i++)
  29.  
  30.     {
  31.  
  32.         printf("%d\n", array[i]);
  33.  
  34.     }
  35.  
  36.     printf("Enter the element to be deleted from array\n");
  37.  
  38.     scanf("%d", &element);
  39.  
  40.     for (i = 0; i < n; i++)
  41.  
  42.     {
  43.  
  44.         if (array[i] == element)
  45.  
  46.         {
  47.             exist = 1;
  48.  
  49.             position = i;
  50.  
  51.             break;
  52.  
  53.         }
  54.  
  55.     }
  56.  
  57.     if (exist == 1)
  58.  
  59.     {
  60.  
  61.         for (i = position; i <  n - 1; i++)
  62.  
  63.         {
  64.  
  65.             array[i] = array[i + 1];
  66.  
  67.         }
  68.  
  69.         printf("array after deletion  \n");
  70.  
  71.         for (i = 0; i < n - 1; i++)
  72.  
  73.         {
  74.  
  75.             printf("%d\n", array[i]);
  76.  
  77.         }
  78.  
  79.     }
  80.  
  81.     else
  82.  
  83.         printf("Given element %d is not exist in the array \n", element);
  84. getch();
  85. }
Output:


delete array element c

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu