C++ Programming Code Examples C++ > Arrays and Matrices Code Examples Insert an element in an array at specific position on the basis of index value Insert an element in an array at specific position on the basis of index value #include<iostream.h> #include<conio.h> void main() { int j,a[5],no,pos; clrscr(); cout<<"Enter data in Array: "; for(j=0;j<5;j++) { cin>>a[j]; } cout<<"\n\nStored Data in Array: "; for(j=0;j<5;j++) { cout<<a[j]; } cout<<"\n\nEnter position to insert number: "; cin>>pos; if(pos>5) { cout<<"\n\nThis is out of range"; } else { cout<<"\n\nEnter new number: "; cin>>no; --pos; for(j=5;j>=pos;j--) { a[j+1]=a[j]; } a[pos]=no; cout<<"\n\nNew data in Array: "; for(j=0;j<6;j++) { cout<<a[j]; } } getch(); }