Skip to content

Instantly share code, notes, and snippets.

Created December 10, 2017 15:54
Show Gist options
  • Save anonymous/cc58a1ebc5432903ee4f1949e5176169 to your computer and use it in GitHub Desktop.
Save anonymous/cc58a1ebc5432903ee4f1949e5176169 to your computer and use it in GitHub Desktop.
Insertion created by ShreySindher - https://repl.it/@ShreySindher/Insertion
#include<stdio.h>
int main()
{
int n,p,j,num;
printf("Enter number of elements: ");
scanf("%d",&n);
int ar[n];
for(int i=0; i<n; i++)
scanf("%d",&ar[i]);
printf("Array is:\n");
for(int i=0; i<n; i++)
printf("%d\t",ar[i]);
printf("\nEnter element to be inserted: ");
scanf("%d",&num);
printf("\nEnter position: ");
scanf("%d",&p);
j=n;
n++;
while(j>=p)
{
ar[j+1] = ar[j];
j--;
}
ar[p] = num;
for(int i=0; i<n; i++)
printf("%d\t",ar[i]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment