Write a c++ program to delete an element from array
#include<iostream>
using namespace std;
#define MAXSIZE 50
int main()
{
int n,a[MAXSIZE],i=0,k=0,position;
cout<<"\n Enter size of array \n";
cin>>n; // read size of array
cout<<"Enter array elements \n";
for (i = 0; i < n; i++) {
cin>>a[i];
}
cout<<" Array elements are : \n";
for (i = 0; i < n; i++) {
cout<<a[i]<<"\t";
}
cout<<"\n Enter the position of element to be deleted \n";
cin>>position;
position = position - 1;
for (i = 0; i < n; i++) {
if (i != position) {
a[k] = a[i];
k++;
}
}
cout<<"Array elements are : \n";
for (i = 0; i < k; i++) {
cout<<a[i]<<"\n";
}
return 0;
}
Output