#include<stdio.h>
#include<conio.h>
void input(int *,int,int);
void input1(int *,int,int);
void traverse(int *,int,int);
int insert(int *,int,int,int);
int elete(int *,int,int);
int pos,ele;
void main()
{
int ub,lb,i,a[10];
clrscr();
printf("program to demonstrate reading,printing,inserting and deleting an element in a linear array");
printf("\n\t-------------------------OUTPUT------------------------");
printf("\n\nenter the lower and the upper bound");
scanf("%d%d",&lb,&ub);
printf("\nenter the elements in the array");
for(i=lb;i<=ub;i++)
scanf("%d",&a[i]);
traverse(a,lb,ub);
input(a,lb,ub);
ub=insert(a,ub,pos,ele);
traverse(a,lb,ub);
input1(a,lb,ub);
ub=elete(a,ub,pos);
traverse(a,lb,ub);
getch();
}
void input(int a[],int lb,int ub)
{
printf("\nenter the element and the position at which the element is to be inserted");
scanf("%d%d",&ele,&pos);
}
void input1(int a[],int lb,int ub)
{
printf("\nenter the position at which the element has to be deleted");
scanf("%d",&pos);
}
void traverse(int a[],int lb,int ub)
{
int i;
printf("\nthe elements in the array are->");
for(i=lb;i<=ub;i++)
printf("\t%d",a[i]);
}
int insert(int a[],int ub,int pos,int ele)
{
int i;
for(i=ub;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=ele;
ub=ub+1;
return(ub);
}
int elete(int a[],int ub,int pos)
{
int i;
for(i=pos;i<=ub;i++)
{
a[i]=a[i+1];
}
ub=ub-1;
return(ub);
}