C Program to Delete an Element from a 1-D Array
#include <stdio.h>
int main() {
int arr[100], n, pos;
// Input size of array
printf("Enter the number of elements in the array: ");
scanf("%d", &n);
// Input array elements
printf("Enter %d elements:\n", n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
// Input position to delete
printf("Enter the position to delete (0-based index): ");
scanf("%d", &pos);
// Shift elements to the left
for (int i = pos; i < n - 1; i++) {
arr[i] = arr[i + 1];
}
n--; // Reduce the size of the array
// Print the updated array
printf("Array after deletion: ");
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}