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

Program to illustrate the concept of templates.

To create an html file to implement the concept of margin, padding using cascading style sheets.

To configure the IP address for a computer connected to LAN