Skip to content

Instantly share code, notes, and snippets.

@78526Nasir
Last active June 2, 2016 18:27
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/e40767bbe86fa2563086548b36959088 to your computer and use it in GitHub Desktop.
Save 78526Nasir/e40767bbe86fa2563086548b36959088 to your computer and use it in GitHub Desktop.
These program is for inserting a new elements into an array !
/// 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