Showing posts with label Inserting Elements In An Array. Show all posts
Showing posts with label Inserting Elements In An Array. Show all posts

Tuesday, 17 January 2012

Inserting 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();
}

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