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 else syntax in c++?
What is the function to call to turn an ascii string into a long?
Explain the scope of resolution operator.
Is c# written in c++?
What is the sequence of destruction of local objects?
What is stream and its types in c++?
What is the basic concept of c++?
How do you import payscale data from non SAP to SAP?is it through LSMW or any other way is there?
Write some differences between an external iterator and an internal iterator? Describe the advantage of an external iterator.
Write a corrected statement in c++ so that the statement will work properly. if (4 < x < 11) y=2*x;
Why c++ is so important?
What are proxy objects in c++?
Can you sort a set c++?
Which is the best c++ compiler for beginners?
How do you differentiate between overloading the prefix and postfix increments?