You are on page 1of 4

1.

INSERTING THE ELEMENT AT ANY LOCATION TO THE ARRAY

#include<iostream.h> #include<conio.h> void main() { int a[10],i,n,loc,item; clrscr(); cout<<"Enter the no of element in the array::::::::::::" ; cin>>n; cout<<"Enter the element in the array:::::::::::" ; for(i=0;i<=n;i++) { cin>>a[i]; } cout<<"Enter the element in the array:::::::::::" ; for(i=0;i<=n;i++) { cout<<a[i]; }

cout<<"Enter the location to which you want to insert::::" ; cin>>loc; cout<<"Enter the element you want to insert::::::::::" ; cin>>item; for(i=n;i>=loc;i--) { a[i+1]=a[i]; a[i]=item;

} n++; cout<<"the new array is:::::::::::" ; for(i=0;i<=n;i++) { cout<<a[i]; } getch(); }

2. DELETING THE ELEMENT FROM THE ARRAY

#include<iostream.h> #include<conio.h> void main() { int a[10],i,n,loc; clrscr(); cout<<"Enter the no of the element in the array::::::::" ; cin>>n; cout<<"Enter the elements in the array::::" ; for(i=0;i<=n;i++) { cin>>a[i]; } cout<<"The array is::::::" ; for(i=0;i<=n;i++) { cout<<a[i]; } cout<<"Enter the location from which you want to delete::::::::::::" ; cin>>loc; for(i=loc;i<=n;i++)

{ a[i]=a[i+1]; } n--; cout<<"The array is::::::" ; for(i=0;i<=n;i++) { cout<<a[i]; } getch(); }

You might also like