DELETE ELEMENT FROM AN ARRAY AT DESIRED POSITION USING C PROGRAM



#include<stdio.h>
int main(){
int a[50],i,pos,size;
printf("\nEnter size of the array: ");
scanf("%d",&size);
printf("\nEnter %d elements in to the array: ",size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);
printf("\nEnter position where to delete: ");
scanf("%d",&pos);
i=0;
while(i!=pos-1)
i++;
while(i<10){
a[i]=a[i+1];
i++;
}
size--;
for(i=0;i<size;i++)
printf(" %d",a[i]);
return 0;
}

15 comments:

Unknown said...

thanks a ton words cannot do justice to what u ve just provided me!!

Anonymous said...

Plz Specify the logic of while loop u used in programs

Jai Sir said...

What will happen if same data is repeated in array. eg 56 98 56 87 23 OR
98 75 75 62 48 37

engr said...

int arr[10]; //10 element int array

for(int i=0; i<10 ; i++)
{
if(arr[i] == key)
{
arr[i] = arr[i+1];
}
}

Anonymous said...

thanx the programs are really helpful for me n ma frnds

Anonymous said...

/* write a program to create an arraylist with string(add,remove)
operation.and value should be enter through keyboard.*/

#include
#include
void main( )
{
char a[50];
int size,pos;
clrscr();
printf("enter the size of the array\n");
scanf("%d",&size);
printf("Enter the elements of the array\n");
for(int i=0;i<size;i++)
scanf("%s",a[i]);
printf("enter the position to be removed");
scanf("%d",&pos);
for(i=pos-1;i<size;i++)
{
a[i]=a[i+1];
}
printf("\nthe element in %d position is removed",pos);
for(i=0;i<size-1;i++)
{
printf("\n%s",a[i]);
}
getch();
}

anwaraj said...

can we do this

printf("Enter element to delete");
scanf("%d",&x)
for(i=0;i<10;i++)
{
if (a[i]==x)
a[i]==a[i+1];
}

Anonymous said...

how can we write a program ,without getting the position from the user such that only the last element gets deleted ???

Anonymous said...

why u used while(i<10) here

Anonymous said...

i want to know delete an array element from the current position in c with explain please.

Anonymous said...

i want to knw delete the middle array elament in c with explanation pls

Anonymous said...

the same question of above all????

Selva said...

Is it possible to delete desired item from STACK ?

Anonymous said...

thnks very much

Unknown said...

anyone explain the quick sort program which is given above plzzzzz