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
Define upcasting.
What are protected members in c++?
Write bites in Turbo c++ Header ("Include") Files.
Suppose that data is an array of 1000 integers. Write a single function call that will sort the 100 elements data [222] through data [321].
What is time_t c++?
What is abstraction with real time example?
Why c++ is better than c language?
What are the advantages of using typedef in a program?
an operation between an integer and real always yeilds a) integer result b) real result c) float result
How const int *ourpointer differs from int const *ourpointer?
How would you obtain segment and offset addresses from a far address of a memory location?
What do you mean by persistent and non persistent objects?
Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.
To which numbering system can the binary number 1101100100111100 be easily converted to?
What methods can be overridden in java?