write a program to insert an element into an array

Answer Posted / harini

#include<iostream>
#include<conio.h>
main()
{
int a[5],b,n,e,i,j;
std::cout<<"enter the no of elements:";
std::cin>>n;
std::cout<<"enter the array elements:";
for(i=0;i<n;i++)
{
std::cin>>a[i];
}
std::cout<<"enter the position of insertion:";
std::cin>>b;
std::cout<<"enter the element to be inserted:";
std::cin>>e;
for(j=n;j>b;j--)
{
a[j]=a[j-1];
}
a[j]=e;
std::cout<<"the new array elements are:\n";
for(j=0;j<=n;j++)
{
std::cout<<a[j]<<"\n";
}
getch();
}

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Comment on c++ standard exceptions?

728


How can you say that a template is better than a base class?

676


What is ios :: in in c++?

735


Define 'std'.

716


How can you quickly find the number of elements stored in a dynamic array?

691






How would you implement a substr() function that extracts a sub string from a given string?

659


What is double in c++?

658


Describe protected access specifiers?

773


Explain what are accessor methods?

759


What is the use of c++ programming language in real life?

653


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create

2154


Is linux written in c or c++?

662


What is c++ good for?

680


Explain how to initialize a const data member.

702


What is the type of this pointer in c++?

727