0% found this document useful (0 votes)
13 views

Delete Element Array

This C program allows users to delete an element from a 1-D array by specifying the position of the element to be removed. It first takes the size of the array and its elements as input, then shifts the elements to the left to fill the gap left by the deleted element. Finally, it prints the updated array after the deletion.

Uploaded by

filmythrill101
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Delete Element Array

This C program allows users to delete an element from a 1-D array by specifying the position of the element to be removed. It first takes the size of the array and its elements as input, then shifts the elements to the left to fill the gap left by the deleted element. Finally, it prints the updated array after the deletion.

Uploaded by

filmythrill101
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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;
}

You might also like