It’s the delete element from an array C program that inputs numbers from the user, and stores these numbers in an array, the user can delete an element from the given array, and print array on the screen.
To understand this program, it’s better you should know the following topics:
Program (1): to delete an element from an array.
#include<stdio.h> #include<conio.h> void main() { int a[100],i,n,p; printf("Enter the number of elements(upto 100) to be entered in the list : ",n); scanf("%d",&n); //accepting values into array for(i=0;i<n;i++) { printf("Enter %d element : ",i+1); scanf("%d",&a[i]); } //position of element to be remove from an array printf("\n Enter the position (1-%d) of element to delete : ",n); scanf("%d",&p); //removing an element for(i=p-1;i<n-1;i++) { a[i]=a[i+1]; } printf("\nElement of the position %d is delete \n",p); //Printing an array a elements after deleting element printf("\nThe New list\n"); for(i=0;i<n-1;i++) { printf("%d\t",a[i]); } getch(); }
Output (1)
Enter the number of elements(upto 100) to be entered in the list : 5 Enter 1 element : 2 Enter 2 element : 4 Enter 3 element : 1 Enter 4 element : 10 Enter 5 element : 7 Enter the position (1-5) of element to delete : 4 Element of the position 4 is delete The New list 2 4 1 7