Delete an element from an array using C

An array of Deletion :

Working – Delete an element from an array

Array for Deletion :

Program

    #include <stdio.h>
    #include <conio.h>
    delete(int arr[],int n,int loc)
    {
    int i;
    for(i=loc;i<n-1;i++)
	{
    arr[i]=arr[i+1];
 
    n--;
    return(n);
     }
    }
   
    void main()
    {
    int arr[10],element,i,n,loc;
    clrscr();
    printf("\n Enter the size of an array");
    scanf("%d",&n);
    printf("\n Enter the element\n");
    for(i=0;i<n;i++)
     scanf("%d",&arr[i]);
      printf("Array elements are");
      for(i=0;i<n;i++)
    	{
  		printf("%d\n",arr[i]);
   		}
    printf("Enter the location to be deletion=");
    scanf("%d",&loc);
      
      n=delete(arr,n,loc);
      printf("Array after insertion");
      for(i=0;i<n;i++)
          printf("%d\n",arr[i]);
            getch();
  }

Output :

Enter the size of an array = 2
    Enter the element 
    23
    12
    Enter the location to be deletion = 1
    Array after deletion
    23

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top