Write a program in C to insert elements in an array
#include<stdio.h>
#include<conio.h>
void main()
{
int num[20],j,p,n,s;
clrscr();
printf(“enter the number of elements\n”);
scanf(“%d”,&n);
printf(“enter the elements of array\n”);
for(j=0;j<n;j++)
scanf(“%d”,&num[j]);
printf(“enter the element and positon to be inserted\n”);
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();
}
Post a Comment