//Program to perform deletion operation in array.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,*data,n,m,a,l,e;
char c;
clrscr();
printf("Enter the number of elements in the array:");
scanf("%d",&n);
data=(int*)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
printf("\nEnter the value of %d element:",i);
scanf("%d",&data[i]);
}
printf("\nArray before deletion");
for(i=0;i<n;i++)
printf("%d, ",data[i]);
a=0;
l=n-1;
printf("\nif u want to delete beginning element then press b");
printf("\nif u want to delete middle element then press m");
printf("\nif u want to delete end element then press e");
printf("\nEnter ur choice: ") ;
c=getche();
switch(c)
{
case 'b':
case 'B':
e=data[0];
for(i=0;i<n-1;i++)
{
data[i]=data[i+1];
}
n=n-1;
break;
case 'm':
case 'M':
m=(a+l)/2;
e=data[m];
for(i=m;i<n-1;i++)
{
data[i]=data[i+1];
}
n=n-1;
break;
case 'e':
case 'E':
e=data[l];
n=n-1;
break;
default:
printf("\nInvalid choice");
getch();
exit(0);
}
printf("\nArray after deletion:");
for(i=0;i<n;i++)
printf("%d, ",data[i]);
printf("\n\n Deleted element is %d",e);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,*data,n,m,a,l,e;
char c;
clrscr();
printf("Enter the number of elements in the array:");
scanf("%d",&n);
data=(int*)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
printf("\nEnter the value of %d element:",i);
scanf("%d",&data[i]);
}
printf("\nArray before deletion");
for(i=0;i<n;i++)
printf("%d, ",data[i]);
a=0;
l=n-1;
printf("\nif u want to delete beginning element then press b");
printf("\nif u want to delete middle element then press m");
printf("\nif u want to delete end element then press e");
printf("\nEnter ur choice: ") ;
c=getche();
switch(c)
{
case 'b':
case 'B':
e=data[0];
for(i=0;i<n-1;i++)
{
data[i]=data[i+1];
}
n=n-1;
break;
case 'm':
case 'M':
m=(a+l)/2;
e=data[m];
for(i=m;i<n-1;i++)
{
data[i]=data[i+1];
}
n=n-1;
break;
case 'e':
case 'E':
e=data[l];
n=n-1;
break;
default:
printf("\nInvalid choice");
getch();
exit(0);
}
printf("\nArray after deletion:");
for(i=0;i<n;i++)
printf("%d, ",data[i]);
printf("\n\n Deleted element is %d",e);
getch();
}