About Me

header ads

Program to delete an element from the array.


Program to delete an element from the array.

#include <stdio.h>
#include<conio.h>
void main()
{
int a[100], pos,i,n;
printf("Enter number of elements in array\n");
scanf("%d",&n);
printf("Enter %d elements\n", n);
for(i=0;i<n;i++)
scanf("%d", &a[i]);
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 (i=pos-1;i<n-1;i++ )
a[i]=a[i+1];
printf("Resultant array is\n");
for(i=0;i<n-1;i++)
printf("%d\n",a[i]);
}
getch();
}

OUTPUT:
Enter number of elements in array
4                  
Enter 4 Elements
7
56
12
48    
Enter the location where you wish to delete element
3
Resultant array is
7
56
48