Created
December 10, 2017 15:54
-
-
Save anonymous/cc58a1ebc5432903ee4f1949e5176169 to your computer and use it in GitHub Desktop.
Insertion created by ShreySindher - https://repl.it/@ShreySindher/Insertion
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
#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