ProAnswers.org

Write a C program to perform inserting elements in an Array ?

#include

#include 

void main() 

{ 

int num[20],j,p,n,s; 

clrscr(); 

printf(“enter the number of elements

”);

scanf(“%d”,&n); 

printf(“enter the elements of array

”);

for(j=0;j

scanf(“%d”,&num[j]); 

printf(“enter the element and positon to be inserted

”);

scanf(“%d%d”,&s,&p); 

p--; 

for(j=n;j!=p;j--) 

{ 

num[j]=num[j-1]; 

} 

num[j]=s; 

for(j=0;j<=n;j++) 

printf(“%d”,num[j]); 

getch(); 

} 

Output: 

enter the number of elements 

4 

enter elements 

1 

2 

3 

5 

enter the element and position to be inserted 

4 

4 

1 2 3 4