C++ Program to Delete an Element From an Array
Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
//Program for remove element from array;
#include<iostream>
#define clrscr() system("cls")
using namespace std;
int main()
{
int a[50],n,i,idx;
clrscr();
input:cout<<"\nEnter the limit: ";
cin>>n;
if(n>50)
{
cout<<"\n Invalid limit pls enter again";
goto input;
}
else
{
cout<<"\n Enter elements in array";
for(i=0;i<n;i++)
cin>>a[i];
cout<<"\n Elements of array\n";
for(i=0;i<n;i++)
{
cout<<"a["<<i<<"]:";
cout<<a[i]<<" ";
}
cout<<"\n Enter index number for delete element";
cin>>idx;
if(idx>n)
cout<<"\nInvalid index number deletion not possible";
else
{
for(i=idx;i<n-1;i++)
{
a[i]=a[i+1];
}
cout<<"\n elements of array after deletion\n";
for(i=0;i<n-1;i++)
{
cout<<"a["<<i<<"]:";
cout<<a[i]<<" ";
}
}
}
}
Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google

