-
-
Save ssindher11/1739dce3e2aa8ca728a2e95c27bf4c0f 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