C Program to Delete an Element from an Array with Explanation

C Program to Delete an Element from an Array with Explanation

In this post I'm gonna share you amazing unique C Program to Delete an Element from an Array. In order to clear all Basics of C Programming you can visit my Full C Programming Course for Free.

Delete an Element from an Array

Deleting an element does not affect the actual size of array. The size of the array remain same as we declare.

C Program to Delete an Element of an Array with user Input:

#include

int main(){

int arr[20];

int arrsize, item, loc;

printf("How Many Elements: "); 

scanf("%d",&arrsize);



for(int i=0; i<arrsize; i++){

    printf("Enter Element %d: ",i+1);

    scanf("%d",&arr[i]);

}

printf("\n");



printf("Enter which Location Element You want to Delete: ");

scanf("%d",&loc);



item=arr[loc-1];



for(int i=loc-1; i<arrsize-1; i++){

    arr[i]=arr[i+1];

}

arrsize--;



printf("At Location %d element %d is Deleted\n\n", loc, item);



printf("Now After Deletion Array Elements:\n");

for(int i=0; i<arrsize; i++){

    printf("Element %d: %d\n",i+1, arr[i]);

}

return 0;

}

Explanation of the program:

Read more...

Original Credit: www.dheerajpatidar.com