Friday 7 August 2015

C Program - Insert an element in an array

C Program Insert an element in an array

#include<stdio.h>
#include<conio.h>
#define max_size 100
void main()
{
int arr[max_size];
int i,n,element,location;
clrscr();
printf("Enter the number of element :- ");
scanf("%d",&n);
printf("\nEnter the elements of array :- \n");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("\nEnter the element :- ");
scanf("%d",&element);
printf("\nEnter the location :- ");
scanf("%d",&location);
for(i=n;i>=location;i--)
{
arr[i]=arr[i-1];
}
n++;
arr[location-1]=element;
printf("\nDisplay array element :- \n");
for(i=0;i<n;i++)
{
printf("%d\n",arr[i]);
}
getch();
}

Output :-


























Back to 'C Language Programs'

No comments:

Post a Comment