1
#include<iostream.h> #include<conio.h> void fun(int a[],int &n,int num,int pos) { for (int i=n;i>=pos-1;i--) a[i]=a[i-1]; a[i+1]=num; n++; } void main() { clrscr(); int a[10],n,num,pos; cout<<"how many nos you want to enter\n "; cin>>n; cout<<"enter "<<n<<" numbers\n"; for (int i=0;i<n;i++) cin>>a[i]; cout<<"enter number to be inserted\n"; cin>>num; cout<<"enter position of no "; cin>>pos; fun(a,n,num,pos); cout<<"new array is "; for (i=0;i<n;i++) cout<<a[i]<<"\n"; getch(); } /*output how many nos you want to enter 5 enter 5 numbers 1 3 5 6 8 enter number to be inserted 7 enter position of no 5 new array is 1 3 5 6 7 8 */

INSERTION C++

Embed Size (px)

DESCRIPTION

PROGRAM IN C++ FOR INSERTION

Citation preview

Page 1: INSERTION C++

#include<iostream.h>#include<conio.h>void fun(int a[],int &n,int num,int pos){for (int i=n;i>=pos-1;i--)a[i]=a[i-1];a[i+1]=num;n++;}void main(){ clrscr();int a[10],n,num,pos;cout<<"how many nos you want to enter\n ";cin>>n;cout<<"enter "<<n<<" numbers\n";for (int i=0;i<n;i++)cin>>a[i];cout<<"enter number to be inserted\n";cin>>num;cout<<"enter position of no ";cin>>pos;fun(a,n,num,pos);cout<<"new array is ";for (i=0;i<n;i++)cout<<a[i]<<"\n";getch();}/*outputhow many nos you want to enter 5enter 5 numbers13568enter number to be inserted7enter position of no 5new array is 135678*/