Home / Programs / C Program to Delete an element from the specified location from Array
🚀 Programming Example

C Program to Delete an element from the specified location from Array

👁 1,193 Views
💻 Practical Program
📘 Step Learning
C Program to Delete an element from the specified location from Array

💻 Program Code

#include<stdio.h>
 
int main() {
   int arr[30], num, i, loc;
 
   printf("\nEnter no of elements :");
   scanf("%d", &num);
 
   //Read elements in an array
   printf("\nEnter %d elements :", num);
   for (i = 0; i < num; i++) {
      scanf("%d", &arr[i]);
   }
 
   //Read the location
   printf("\n location of the element to be deleted :");
   scanf("%d", &loc);
 
   /* loop for the deletion  */
   while (loc < num) {
      arr[loc - 1] = arr[loc];
      loc++;
   }
   num--;  // No of elements reduced by 1
 
   //Print Array
   for (i = 0; i < num; i++)
      printf("\n %d", arr[i]);
 
   return (0);
}
                        

🖥 Program Output


Enter no of elements :5

Enter 5 elements :1
2
3
4
5

 location of the element to be deleted :3

 1
 2
 4
 5 
                            

📘 Explanation

none
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.