Write a program to insert a new element at end as well as at a given position in an array.

#include<iostream>
using namespace std;
int main()
{
int arr[50],size,insert,i,pos;
cout<<"Enter the array size\n";
cin>>size;
cout<<"Enter Array elements\n";
for(i=0;i<size;i++)
{
cin>>arr[i];
}
cout<<"Enter The element to be inserted\n";
cin>>insert;
cout<<"At which position(Enter the index number)\n";
cin>>pos;
for(i=size;i>pos;i--)
{
arr[i]=arr[i-1];
}
arr[pos]=insert;
cout<<"Inserted Successfully!!\n"<<"Now the new array\n";
for(i=0;i<size+1;i++)
{
cout<<arr[i]<<" ";
}
   cout<<"\n/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";
}

Output:



Comments

Popular posts from this blog

To implement the various components of HTML5 Canvas

Program to illustrate the concept of templates.

Program to illustrate the order of execution of constructors and destructors in inheritance.