C Program to Delete an element from the specified location from Array
Program :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include<stdio.h> int main() { int arr[30], num, i, loc; printf("\nEnter no of elements :"); scanf("%d", &num); //Read elements in an array printf("\nEnter %d elements :", num); for (i = 0; i < num; i++) { scanf("%d", &arr[i]); } //Read the location printf("\n location of the element to be deleted :"); scanf("%d", &loc); /* loop for the deletion */ while (loc < num) { arr[loc - 1] = arr[loc]; loc++; } num--; // No of elements reduced by 1 //Print Array for (i = 0; i < num; i++) printf("\n %d", arr[i]); return (0); } |