Insert an Element into an array














Input: Key is item,location is the index of the element  where is to be inserted.
Output: Array enriched with key
--------------------------------------------
--------------------------------------------
//Insert a data into array
#include<stdio.h>
int main()
{
int a[100],n,i,e,l;
printf("\nEnter  total no of elements :");
scanf("%d", &n);
for(i=0;i<n;i++)
{
scanf("%d", &a[i]);

}

printf("\nEnter the element to be inserted :");
scanf("%d", &e);
printf("\nEnter the location:");
scanf("%d", &l);
for(i=n;i>=l;i--)
{
a[i] = a[i - 1];
}
n++;
a[l- 1] = e;

for (i = 0; i < n; i++)
{


printf("\t%d", a[i]);
}
return 0;

}

(By:shahimtiyaj)
SHARE

Shah Imtiyaj

Try to know thyself

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

একটি মন্তব্য পোস্ট করুন