PROGRAM TO INSERT AN ELEMENT IN AN ARRAY

Sunday, April 6, 2014

#define MAX 10
main()
{
int a[MAX]={11,22,33,44,55,77,88};
int n,x;
printf("Enter an element to be inserted
");

scanf("%d",&x);
printf("Enter the position at which
");

printf("this element to be inserted
");

scanf("%d",&n);
insert(a,x,n);
}


insert(int *a,int x,int n)
{
int i,j=0,*a1,temp;
a1=(int*)malloc((MAX-n)*sizeof(int));
for(i=n;i<MAX;i++)
*(a1+j++)=*(a+i);
*(a+n)=x;
for(i=n+1;i<MAX;i++)
*(a+i)=*(a1++);
for(i=0;i<MAX;i++)
printf("%d",*(a+i));
putchar(
);

}

OUTPUT
Enter an element to be inserted 
66
Enter the position at which
this element to be inserted 
3
11   22   33   66   44   55   77   88   0   0

Related Posts by Categories

0 comments:

Post a Comment

Copyright © 2014 Information Sharing | Powered By Blogger