write a program to insert an element into an array
Answer Posted / prasoon
#include<iostream.h>
#include<conio.h>
void main()
{
int *p,n,item,pos;
clrscr();
cout<<"\nEnter the number of elements in the array: ";
cin>>n;
p=new int[n+1];
cout<<"\nEnter the elements: \n";
for(int i=0;i<n;i++)
cin>>p[i];
cout<<"\nThe entered elements are: \n\n";
for(i=0;i<n;i++)
cout<<p[i]<<"\t";
cout<<"\nEnter the item to be inserted: ";
cin>>item;
cout<<"\nEnter its position: ";
cin>>pos;
for(i=n;i>=pos;i--)
p[i]=p[i-1];
p[pos-1]=item;
n++;
cout.flush();
cout<<"\nThe modified array is:\n\n";
for(i=0;i<n;i++)
cout<<p[i]<<"\t";
delete p;
getch();
}
| Is This Answer Correct ? | 162 Yes | 51 No |
Post New Answer View All Answers
What is the purpose of ios::basefield in the following statement?
Is c++ primer good for beginners?
What is the basic concept of c++?
Explain the use of vtable.
Can I learn c++ without learning c?
What is a map in c++?
What is the use of object in c++?
What is the best c++ compiler?
Describe the role of the c++ in the tradeoff of safety vs. Usability?
Is the declaration of a class its interface or its implementation?
How many namespaces are there in c++?
Evaluate the following expression as C++ would do :8 * 9 + 2 * 5 a) 82 b) 79 c) 370 d) list
Is it possible to provide default values while overloading a binary operator?
Is turbo c++ free?
Give an example of run-time polymorphism/virtual functions.