Last active
June 2, 2016 18:27
-
-
Save 78526Nasir/e40767bbe86fa2563086548b36959088 to your computer and use it in GitHub Desktop.
These program is for inserting a new elements into 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
/// insert new elements into an array /// | |
#include <stdio.h> | |
main() | |
{ | |
int a[100],n,pos,item,i; | |
printf("Enter how many elements :"); | |
scanf("%d",&n); | |
printf("Enter %d elements values :",n); | |
for(i=0;i<n;i++) | |
scanf("%d",&a[i]); | |
printf("Enter an element to insert :"); | |
scanf("%d",&item); | |
printf("Enter an position to insert the element :"); | |
scanf("%d",&pos); | |
printf("Before inserting new element :\n"); | |
for(i=0;i<n;i++) | |
printf("%d ",a[i]); | |
/*insert new element */ | |
for(i=n;i>=pos;i--) | |
a[i]=a[i-1]; | |
a[pos-1]=item; | |
n++; | |
printf("\nAfter inserting new 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