Wednesday, January 6, 2021

Delete Element from array in c++ with Eaglesoft programmers

 


#include <iostream>
using namespace std;
int main()
{
    int array[5] = {4, 3, 2, 5, 6};
    int p;
    cout << "Before delete element" << endl;
    for (int i = 0; i < 5; i++)
    {
        cout << "Value of array[" << i << "] " << array[i] << endl;
    }
    cout << "Enter position of element that you want to delete:" << endl;
    cin >> p;
    for (int i = p; i < 5; i++)
    {
        array[i] = array[i + 1];
    }
    cout << "After delete element" << endl;
    for (int i = 0; i < 4; i++)
    {
        cout << "Value of array[" << i << "] " << array[i] << endl;
    }
    return 0;
}

No comments:

Post a Comment