In this tutorial you will learn about the C++ Program to Delete Array Element and its application with practical example.
C++ Program to Delete Array Element
In this tutorial, we will learn to create a C++ program that will delete the element of Array using C++ programming.
Before starting with this tutorial we assume that you are best aware of the following C++ programming topics:
- Operators in C++ Programming.
- Basic Input and Output function in C++ Programming.
- Basic C++ programming.
- For loop in C++ Programming.
Program for Delete the element of Array:-
An array is a collection of similar data type elements. In today’s program, we will take an array in input from the user and then we will take the element for deleting from the array. After deleting the element from the array we will reprint the array.
Algorithm for program:-
Step 1. Initialize the required variable for the program.
Step 2. Take size of array in input from the user.
Step 3. Taking the elements of the array from the user.
Step 4. Taking the location of the deleting element.
Step 5. Deleting the element from the array.
Step 6. Print the resultant array on the screen.
Step 7. End program.
To Delete an element from the array
using namespace std;
//declaring the variables for the program
int arr, tot=10, i, elem, j, found=0;
//Taking input from the user
cout<<"Enter 10 Array Elements: ";
for(i=0; i<tot; i++)
//taking deletion element from the user
cout<<"\nEnter Element to Delete: ";
for(i=0; i<tot; i++)
for(j=i; j<(tot-1); j++)
arr[j] = arr[j+1];
//printing the deletion message for the element
cout<<"\nElement doesn't found in the Array!";
cout<<"\nElement Deleted Successfully!";
In the above program, we have first initialized the required variable.
- arr = it will hold the elements in an array.
- tot = it will hold the number of elements in an array.
- i = it will hold the integer value to control the array.
- Elem = it will hold the location for delete element size of the array.
Taking input from the user in an array of elements.
Deleting the array element.
Printing the Program Code