Delete element in array

Q. Write a C program to delete a value or element in array and user should guide which value is deleted.


Ans.


/*c program for delete a number in array*/
#include<stdio.h>
#include<conio.h>

#define SIZE 50
int main()
{
 int arr[SIZE];
 int i,num,index;
 printf("Enter total number of element in array : ");
 scanf("%d", &num);
 for(i=0; i<num; i++)
 {
  printf("Enter %d element : ",i+1);
  scanf("%d",&arr[i]);
 }
 printf("
Enter element number which you want to delete : "
);

 scanf("%d", &index);
 if(index >= num+1)
   printf("
Element not found!!"
);

 else
 {
  for(i=index-1; i<num-1; i++)
     arr[i]=arr[i+1];
  printf("
-- After deletion new array list --

"
);

  for(i=0; i<num-1; i++)
    printf(" %d
"
,arr[i]);

 }
 getch();
 return 0;
}


/*************** Output *****************/
Screen shot of delete element in array




Related Programs:

  1. How to create array in C?
  2. How to calculate length of array?
  3. Insert new element in array
  4. Display array in reversing order
  5. Example of array C program

Related Posts by Categories

0 comments:

Post a Comment