C Program to delete element at end of Array

To delete an element from the end in an array, we will just reduce the size of an array by one. After reducing the size we will print the array and will find that the last element is not printing. It means that the element is not in the array now.

C Program to delete element at end of Array

#include <stdio.h>
void main()
{
    int position, i, n, value,ch;
    printf("C Program to delete element at end of Array\n");
    printf("First enter number of elements you want in Array\n");
    scanf("%d", &n);
    int arr[n];
   for(i = 0; i < n; i++)
    {
        printf("Please give value for index %d : ",i);
        scanf("%d",&arr[i]);
    }
    value=arr[n-1]; //assigning last value in value variable
    printf("Element %d is deleting at %d index \n",value,n-1);
    n=n-1;//here decreasing value to reduce size of array
    printf("New Array after deleting element at end \n ");
    for(i = 0; i < n; i++)
    {
       printf("%d \t",arr[i]);
    }
}

Output

C Program to delete element at end of Array

Share on

Also Prepare Below Important Question

Interview Questions Categories

C Programming Interview Preparation

Core Java Programming Interview Preparation

Python Programming Interview Preparation