C program to Delete an Element in Array at any location

Write a  C program to Delete an Element in Array at any location:

Required Knowledge:

C basics, Arrays

Program:

 1 #include<stdio.h>
 2  void delete(int);
 3  int static size=5;
 4  int arr[5];
 5  void main()
 6  
 7  {
 8      int i,position,e,d;
 9      printf("Enter the elements of array:\n");
10      for(i=0; i<size; i++)
11      scanf("%d",&arr[i]);
12  
13      printf("\nThe elements are:");
14      for(i=0; i<size; i++)
15      printf("%d ",arr[i]);
16  
17      printf("\nEnter the index no to delete the element:"); //index no start from 0
18      scanf("%d",&d);
19  
20      delete(d);
21  }
22  
23  void delete(d)
24  {
25      int i;
26      for(i=d-1; i<size-1; i++)
27      {
28          arr[i]=arr[i+1];
29  
30      }
31      size--;
32      printf("\nThe elements are:");
33      for(i=0; i<size; i++)
34          printf("% d",arr[i]);
35  }

Output:


Comments

Popular posts from this blog

C program to calculate velocity

C program to find square root of a number

C program to find maximum between two numbers