Chapter:

Arrays-

Write a program in C to delete an element at desired position from an array.

Write a program in C to delete an element at desired position from an array.

#include <stdio.h>
void main()
{
  int arr1[50],i,pos,n;
  printf("\n\nDelete an element at desired position from an array :\n");
     printf("---------------------------------------------------------\n");  
  
  printf("Input the size of array : ");
  fflush(stdout);
  scanf("%d", &n);
    /* Stored values into the array*/
   printf("Input %d elements in the array in ascending order:\n",n);
   for(i=0;i<n;i++)
     {
	   printf("element - %d : ",i);
	   fflush(stdout);
	   scanf("%d",&arr1[i]);
      }
  printf("\nInput the position where to delete: ");
  fflush(stdout);
  scanf("%d",&pos);
/*---- locate the position of i in the array -------*/
  i=0;
  while(i!=pos-1)
  {
            i++;
  }
/*---- the position of i in the array will be replaced by ....
Show More

All Chapters

View all Chapter and number of question available From each chapter from C-programming-