Program for Deletion of an element in an array.

# include<stdio.h> #include<conio.h> void main() { int a[10],i, j, n , pos , n; printf ( “enter size of an array”)...

# include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i, j, n , pos , n;
printf ( “enter size of an array”);
scanf ("%d", & n);
printf ( “enter elements into an array”);
for ( i =0, i < n ; i ++)
scanf (“%d”, & a[i]);
printf (“enter position to be deleted”);
scanf (“%d”, & pos);
if( (pos>n-1 ) || ( pos < 0 ) )
{
  printf("out of bound");
  exit(0);
}
for ( j = pos; j < n-1; j ++)
{
    a [j]=a[j+1];
}
n=n-1;
printf("\n Elements after deletion");
for (i = 0; i < n; i ++)
printf (“%2d”, a[i]);
getch();
}

OP:
enter size of an array 6
enter elements into an array
 5
1
3
4
5
6
enter position to be deleted 2
Elements after deletion 5 1 4 5 6


Related

C Programs 7582674807664951264

Post a Comment

emo-but-icon

item