C Program to delete an element from array by position

Simple C program to delete element from array: To delete an element from an array, first we will remove element from array and after that we will shift array element towards left.
 
/* C program to delete array from array by position */
#include<stdio.h>
int main()
{
 int arr[100],n,i,position;
 printf("Enter a number for elements: ");
 scanf("%d",&n);
 printf("Enter %d elements:\n",n);
 for(i=0;i<n;i++)
 {
  scanf("%d",&arr[i]);
 }
 printf("Enter position from which you want to delete: ");
 scanf("%d",&position);
 for(i=position-1;i<n-1;i++)
 {
  arr[i]=arr[i+1];
 }
 printf("Array: \n");
 for(i=0;i<n-1;i++)
 {
  printf("%d ",arr[i]);
 }
 return 0;
}
/* End of the program */
 



Popular posts from this blog