Tuesday, 14 March 2017

Insertion In Array by Pointers C++ Program Exampe

#include<iostream>
using namespace std;
#include<conio.h>
 main()
{
int num[50],n, num1, i, pos,*p;
cout<<"Enter Array Size : ";
cin>>n;
cout<<"Enter Numbers : ";
for(i=0; i<n; i++)
cin>>num[i];
p=num;
cout<<"Enter Number to be inserted : ";
cin>>num1;
cout<<"Enter position :";
cin>>pos;
for(i=n; i>pos; i--)
{
*(p+i)=*(p+i-1);
}
*(p+pos)=num1;
for(i=0; i<n+1; i++)
{
cout<<*(p+i)<<" ";
}
getch();
}


No comments:

Post a Comment

Amazon1Ads