programming-examples/c/Arrays/C Program to Delete the Specified Integer from an Array.c
2019-11-15 12:59:38 +01:00

69 lines
1.4 KiB
C

/*
* C program to accept an array of integers and delete the
* specified integer from the list
*/
#include <stdio.h>
void main()
{
int vectorx[10];
int i, n, pos, element, found = 0;
printf("Enter how many elements\n");
scanf("%d", &n);
printf("Enter the elements\n");
for (i = 0; i < n; i++)
{
scanf("%d", &vectorx[i]);
}
printf("Input array elements are\n");
for (i = 0; i < n; i++)
{
printf("%d\n", vectorx[i]);
}
printf("Enter the element to be deleted\n");
scanf("%d", &element);
for (i = 0; i < n; i++)
{
if (vectorx[i] == element)
{
found = 1;
pos = i;
break;
}
}
if (found == 1)
{
for (i = pos; i < n - 1; i++)
{
vectorx[i] = vectorx[i + 1];
}
printf("The resultant vector is \n");
for (i = 0; i < n - 1; i++)
{
printf("%d\n", vectorx[i]);
}
}
else
printf("Element %d is not found in the vector\n", element);
}
/*
Enter how many elements
4
Enter the elements
345
234
678
987
Input array elements are
345
234
678
987
Enter the element to be deleted
234
The resultant vector is
345
678
987