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

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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