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:

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

    ReplyDelete
  2. Plz Specify the logic of while loop u used in programs

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

    ReplyDelete
  4. int arr[10]; //10 element int array

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

    ReplyDelete
  5. thanx the programs are really helpful for me n ma frnds

    ReplyDelete
  6. /* 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();
    }

    ReplyDelete
    Replies
    1. thnks very much

      Delete
  7. 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];
    }

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

    ReplyDelete
  9. why u used while(i<10) here

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

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

    ReplyDelete
  12. the same question of above all????

    ReplyDelete
  13. Is it possible to delete desired item from STACK ?

    ReplyDelete
  14. anyone explain the quick sort program which is given above plzzzzz

    ReplyDelete