Write c program takes input from the user and deletes the element from an array. if the specified element is present multiple times then delete all the elements.
#include<stdio.h>
int main()
{
int i,j,n,a[50],size;
printf("\nenter size of array:");
scanf("%d",&size);
printf("\nenter the array element:");
for(i=0;i<size;i++)
{ scanf("%d",&a[i]); }
printf("\nenter number for deletion:");
scanf("%d",&n);
for(i=0;i<size;i++)
{
/* check element present in array*/
if(a[i]==n)
{
/* Copy next element value to current element so that current value will delete */
for(j=i;j<size;j++)
a[j]=a[j+1];
/* Decrement array size */
size-=1;
}
}
printf("after deletion of element, array became:");
for(i=0;i<size;i++)
{
printf("%d\t",a[i]);
}
return 0;
}
enter size of array:6 enter the array element:1 3 2 3 5 1 enter number for deletion:3 after deletion of element, array became:1 2 5 1