Sample C Program For Deleting An Element From An Array.


#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define S 6

main()
{

int arr[S];
int i, pos, num, j;
clrscr();

for( i = 0; i < S; i++ )
  {
     printf(" \nEnter a[%d] element: ", i );
     scanf(" %d ", &arr[i] );
  }

printf(" \n\nArray is\n\n ");

for( i = 0; i < S; i++ )
     printf(" %2d ", arr[i] );

printf(" \nEnter the position of the element which you would like to delete\n");

scanf(" %d ", &pos );

if( pos > = S + 1 )
    printf(" Deletion not possible.\n ");
else
  {
    for ( i = pos - 1 ; i < S - 1 ; i++ )
           array[c] = array[i+1];
    printf(" Array after deletion\n");
    for( i = 0 ; i < S - 1 ; i++ )
           printf(" %d\n ", array[i] );
  }
getch();

}

OUTPUT:


Enter a[0] element: 1

Enter a[1] element: 6

Enter a[2] element: 7

Enter a[3] element: 4

Enter a[4] element: 3

Enter a[5] element: 8

Array is
1 6 7 4 3 8
Enter the position of the element which you want to delete
4
Array after deletion
16748


Comments

Post a Comment

Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...

Experienced guys can share their resumes at administrator@abapmadeeasy.com/admin@abaper.in

Popular Posts