C program to delete an element from an array in any position .

Following code will delete an element from an array in any position.

Compiled with DEV C++

#include <stdio.h>
#include <conio.h>
int main()
{
  int a[50],i,pos,size;
 
  printf(“\nEnter size of the array: “);
  scanf(“%d”,&size);
  printf(“\nEnter %d elements in to the array: “,size);
  for(i=0;i<size;i++)
            scanf(“%d”,&a[i]);
  printf(“\nEnter position where to delete: “);
  scanf(“%d”,&pos);
  i=0;
  while(i!=pos-1)
            i++;
  while(i<10)
  {
            a[i]=a[i+1];
            i++;
  }
  size–;
  printf(“\nAfter implementation”);
  for(i=0;i<size;i++)
            printf(“\n%d”,a[i]);
  getch();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s