Last active
June 2, 2016 18:36
-
-
Save 78526Nasir/e35ce99ea42414a8287ee0013fc42915 to your computer and use it in GitHub Desktop.
Delete an element from an array !
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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