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 create an html page with frames and frameset

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

1. To familiarize with network devices like switch, hub, routers and bridges in LaTex