Skip to content

Instantly share code, notes, and snippets.

@78526Nasir
Last active June 2, 2016 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 78526Nasir/e35ce99ea42414a8287ee0013fc42915 to your computer and use it in GitHub Desktop.
Save 78526Nasir/e35ce99ea42414a8287ee0013fc42915 to your computer and use it in GitHub Desktop.
Delete an element from an array !
/// Delete an elements from an array ///
#include <stdio.h>
main()
{
int a[5]={1,2,3,4,5},n=5,pos,item,i,j;
printf("Enter an position to delete an element:");
scanf("%d",&pos);
printf("Before deleting element :\n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
if(pos>n)
{
printf("\nOut of Bound ! this position doesn't exists !!");
exit(0);
}
else if(pos==n-1)
n--;
else
{
for(j=pos-1;j<=n;j++)
a[j]=a[j+1];
n--;
}
printf("\nAfter deleting elements :\n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment