Thursday, 26 June 2014

C++ program to delete an element from array


Here is a C++ program to delete an element from array


 SOURCE CODE OUTPUT
#include<iostream>
using namespace std;
int main()
{
    int a[20],num,n;
    cout<<"How many elements to be stored (max 20) : ";
    cin>>num;
    cout<<"Enter elements ";
    for(int i=0;i<num;i++)
       cin>>a[i];
    cout<<"Enter position of element to be deleted ";
    cin>>n;
    for(int y=n-1;y<num;y++)
        a[y]=a[y+1];
    cout<<"After deleting : ";
    for(int i=0;i<num-1;i++)
        cout<<a[i]<<" ";
    return 0;
}

Any questions regarding to program please write in comments.

No comments:

Post a Comment