C Program to Delete an Element in an Array

C Program to Delete an Element in an Array

C program to delete an element in an array; Through this tutorial, we will learn how to delete elements in an array in c programs.

C Program to Delete an Element in an Array

#include <stdio.h>
 
int main()
{
	int Array[10], Position, i, Size;
	
	printf("\n Please Enter Number of elements in an array :- ");
	scanf("%d", &Size);
	
	printf("\n Please Enter %d elements of an Array :- ", Size);
	for (i = 0; i < Size; i++)
	{
    	scanf("%d", &Array[i]);
   	}     
 
  	printf("\n Please Enter a Valid Index Position of a Element that you want to Delete :- ");
  	scanf("%d", &Position);
  	
	if(Position < 0 || Position >= Size)
  	{
  		printf("\n Please Enter a Valid Index Position between 0 and %d", Size-1);
  	}
  	else
  	{
  		for (i = Position; i < Size; i++)
   		{
	    	Array[i] = Array[i + 1];
   		}
   		Size--;
	}
 	printf("\n Final Array after Deleteing an Array Elemnt is :- ");
 	for (i = 0; i < Size; i++)
  	{
 		printf("%d\t", Array[i]);
  	}	     
 	return 0;
}

The output of the above c program; as follows:

Please Enter Number of elements in an array :- 5
Please Enter 5 elements of an Array :- 1 2 3 4 5
Please Enter a Valid Index Position of a Element that you want to Delete :- 2
Final Array after Deleteing an Array Elemnt is :- 1	2	4	5

Recommended C Programs

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *