0% found this document useful (0 votes)
34 views3 pages

#Include #Include Void Int

The document discusses C++ code to insert and delete elements from an array. It contains code to: 1) Accept the size and elements of an array from the user. 2) Accept the element and location to insert and insert the element by shifting existing elements. 3) Accept the location to delete an element, store the element, shift elements and decrement the size.

Uploaded by

arjun_ct786
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views3 pages

#Include #Include Void Int

The document discusses C++ code to insert and delete elements from an array. It contains code to: 1) Accept the size and elements of an array from the user. 2) Accept the element and location to insert and insert the element by shifting existing elements. 3) Accept the location to delete an element, store the element, shift elements and decrement the size.

Uploaded by

arjun_ct786
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<iostream.h> #include<conio.h> void main() { int a[100],n,i,temp; clrscr(); cout<<"enter no.

of elements:"; cin>>n; cout<<"enter elements:"; for(i=0;i<n;i++) cin>>a[i]; cout<<"enter an element which you want to insert in a array:"; cin>>item; cout<<"enterthe location where you want to insert an element in a array:"; cin>>loc; for(i=loc;i>=loc;i--) a[i+1]=a[i]; a[loc]=item; n=n+1; cout<<"no. of element:<<n; cout<<"list after inserting an element is:"<<endl; for(i=0;i<n;i++) cout<<a[i]<<"\t"; getch(); }

#include<iostream.h> #include<conio.h> void main() { int a[100],n,i,loc,item; clrscr(); cout<<"enter no. of elements:"; cin>>n; cout<<"enter elements:"; for(i=0;i<n;i++) cin>>a[i]; cout<<"enter an element which you want to insert in a array:"; cin>>item; cout<<"enterthe location where you want to insert an element in a array:"; cin>>loc; for(i=n;i>=loc;i--) a[i+1]=a[i]; a[loc]=item; n=n+1; cout<<"no. of element:"<<n; cout<<"list after inserting an element is:"<<endl; for(i=0;i<n;i++) cout<<a[i]<<"\t"; }

/*delete an element in array*/ #include<iostream.h> #include<conio.h> void main() { int a[100],item,n,i,loc; clrscr(); cout<<"enter no. of elements:"; cin>>n; cout<<"enter elements:"; for(i=0;i<n;i++) cin>>a[i]; cout<<"enter the location from where you want to delete an element:"; cin>>loc; item=a[loc]; for(i=loc;i<n;i++) a[i]=a[i+1]; n=n-1; cout<<"no. of elements:"<<n<<endl; cout<<"elements are:"<<endl; for(i=0;i<n;i++) cout<<a[i]<<"\t"; getch(); }

You might also like