Program to delete a value from a given array from a given position

Deletion from a position in an array:

Deletion of a value is straightforward, since the elements from the given position are overwritten with the subsequent elements upto the last element, last element is initialized with zero and variable n indicating total number of elements is decremented by one.

/* Deletion from a position */

#include <stdio.h>

#define MAX 10

int main(){
int arr[MAX],i,n,pos;
printf(“nEnter total numbers?”);
scanf(“%d”,&n);
for(i=0;i<n;i++){
printf(“nEnter number?”);
scanf(“%d”,&arr[i]);
}
printf(“nEnter the position from where to delete element?”);
scanf(“%d”,&pos);
for(i=pos;i<n;i++)
arr[i] = arr[i+1];
arr[i] = 0;
n–;
printf(“nArray elements after deletion:”);
for(i=0;i<n;i++)
printf(“%dt”,arr[i]);
}