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
When does a name clash occur in c++?
What is insertion sorting?
How do you add an element to a set in c++?
Explain the different access specifiers for the class member in c++.
What is std namespace in c++?
What are the classes in c++?
What do c++ programmers do?
What do you mean by vtable and vptr in c++?
What are the advantages of using pointers in a program?
What is encapsulation in c++ with example?
What is type of 'this' pointer? Explain when it is get created?
How const int *ourpointer differs from int const *ourpointer?
How would you implement a substr() function that extracts a sub string from a given string?
What is the extraction operator and what does it do?
What is the use of main function in c++?