Code to delete an element from an array in C++
#include <bits/stdc++.h>
using namespace std;
int a[100000];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
int index;
cin >> index;
n--;
for (int i = index; i <= n ; i++)
{
a[i] = a[i + 1];
}
for (int i = 1; i <= n; i++)
{
cout << a[i] << " ";
}
}
Top comments (0)