Program to delete a value in an array

/* Delete a value in an array  */

#include<stdio.h>

#include<conio.h>

void main()

{

int a[100],i,n,pos,x,flag=0;

clrscr();

printf(“enter how many value in array\n”);

scanf(“%d”,&n);

printf(“Enter %d value \n”,n);

for(i=0;i<n;i++)

scanf(“%d”,&a[i]);

printf(“Which value to be delete ->”);

scanf(“%d”,&x);

/* Determine the Search Value */

for(i=0;i<n;i++)

if(x==a[i])

{

pos =i;

flag=1;

break;

}

if(flag ==1)

{

printf(“Your Exist List is :\n “);

for(i=0;i<n;i++)

printf(“%5d”,a[i]);

/* Left shifting */

for(i=pos;i<n;i++)

a[i]=a[i+1];

printf(“\n\nAfter Insert the list is :\n “);

for(i=0;i<n-1;i++)

printf(“%5d”,a[i]);

}

else

{

printf(“Data value not found \n”);

}

getch();

}

 

Mohit Arora
Follow me