ALGORITHM

  1. Ask for the element to be removed.
  2. Perform a search algorithm (binary or linear) to check the validity of the inserted element.
  3. If the element exist then perform the 4th step or else go to step 5.
  4. Shift all the elements from index + 1 to it’s left position i.e. index - 1. this will reduce the array size and overlap with the existing element in the position.
  5. Otherwise print “element not found”
  6. exit

SOURCE CODE

#include <stdio.h>  
#include <conio.h>  
  
int main ()  
{
    int arr[50];  
    int pos, i, num;  
    printf (" \\n Enter the number of elements in an array: \\n ");  
    scanf (" %d", &num);  
      
    printf (" \\n Enter %d elements in array: \\n ", num);  
      
    for (i = 0; i < num; i++ ){   
        printf ("arr[%d] = ", i);  
        scanf ("%d", &arr[i]);  
    }  
    printf( " Define the position of the array element where you want to delete: \\n ");  
    scanf (" %d", &pos);  

    if (pos >= num+1){  
        printf (" \\n Deletion is not possible in the array.");  
    }  
    else{   
        for (i = pos - 1; i < num -1; i++)  
        {  
            arr[i] = arr[i+1]; 
        }  
            
        printf (" \\n The resultant array is: \\n");  
            

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