Ad Code

C Program to delete an element at desired position.

 Write a C Program to delete an element at desired position.


#include <stdio.h>
#include <conio.h>
void main( )
{
clrscr();
int array[100], position, i, n;
printf("Enter number of elements in array\n");
scanf("%d", &n);
printf("Enter %d elements\n", n);
for (i = 0; i < n; i++)
scanf("%d", &array[i]);
printf("Enter the location where you wish to delete element\n");
scanf("%d", &position);
if (position >= n+1)
printf("Deletion not possible.\n");
else
{
for (i = position - 1; i < n - 1; i++)
array[i] = array[i+1];
printf("After deletion of array:\n");
for (i = 0; i < n - 1; i++)
printf("%d\n", array[i]);
}
getch( );
}

Post a Comment

0 Comments

Ad Code