C Program to Delete an element from the specified location from Array
C Programming Language Array in C Language (Article) Array in C Language (Program)
1568Program:
/* C Program to Delete an element from the specified location from Array Author: atnyla Developer */ #include 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); }
Output:
Enter no of elements :5 Enter 5 elements :5 4 3 2 1 location of the element to be deleted :3 5 4 2 1
Explanation:
C Program to Delete an element from the specified location from Array
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.