Deleting an element in an array.
C++
/*Write a C++ program to delete an element from array at specified position.*/
#include<iostream>
using namespace std;
void Delete(int arr[],int size,int position)
{
int i;
for(i=position;i<size;i++)
{
arr[i]=arr[i+1];
}
cout<<"Array elements After Deletion : ";
for(i=0;i<size;i++)
{
cout<<arr[i]<<" ";
}
}
int main()
{
int size;
// cout<<"Input the size of the array : ";
cin>>size;
int position;
int arr[size];
// cout<<"Input the array elements : ";
for(int i=0;i<size;i++)
{
cin>>arr[i];
}
size--;
cout<<"Original Array Before Deletion : ";
for(int i=0;i<size;i++)
{
cout<<arr[i]<<" ";
}
// cout<<endl<<"Positon of element to delete : ";
cin>>position;
Delete(arr,size,position);
return 0;
}
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.