C Program to delete an element from a specified location of an array
Program
#include<stdio.h>
void main()
{
int arr[30], num, i, loc;
printf("Enter no of elements:\t");
scanf("%d", &num);
printf("Enter %d elements:\n", num);
for (i = 0; i < num; i++)
{
scanf("%d", &arr[i]);
}
printf("Enter the location of the element to be deleted:\t");
scanf("%d", &loc);
while (loc < num)
{
arr[loc - 1] = arr[loc];
loc++;
}
num--;
for (i = 0; i < num; i++)
printf("%d\n", arr[i]);
}
Output
Enter no of elements: 7
Enter 7 elements:
12
90
757
36
6868
23
686
Enter the location of the element to be deleted: 4
12
90
757
6868
23
686