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
What is a float in c++?
What is a namespace in c++?
Why would you use pointers in c++?
What is the best it certification?
What are the uses of c++ in the real world?
What is using namespace std in c++?
What is the c++ programming language used for?
What is tellg () in c++?
What you know about structures in C++?
Why c++ does not have finally?
What do you mean by late binding?
Describe the advantages of operator overloading?
What are the differences between malloc() and calloc()?
What are the stages in the development cycle?
What is atoi in c++?