write a program to insert an element into an array
Answer Posted / anupriya garg( sviet)
#include<iostream.h>
void main()
{
int a[60],n,item,pos;
cout<<"enter the no. of elements in array";
cin>>n;
cout<<"enter the elements";
for(int i=0;i<=n;i++)
{
cin>>a[i];
}
for(int i=0;i<=n;i++)
{
cout<<a[i];
}
cout<<"enter the item to be inserted";
cin>>item;
cout<<"enter the position";
cin>>pos;
for(int i=n;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=item;
n=n+1;
cout<<"the modified array is ;\n\n";
for(int i=1;i<=n;i++)
cout<<a[i];
}
| Is This Answer Correct ? | 15 Yes | 9 No |
Post New Answer View All Answers
Should I learn c or c++ first?
Explain the volatile and mutable keywords.
What are the rules for naming an identifier?
Are c and c++ similar?
Explain what is class definition in c++ ?
Explain selection sorting. Also write an example.
Explain how overloading takes place in c++?
Why is it necessary to use a reference in the argument to the copy constructor?
What are the advantages of inheritance in c++?
Is c++ vector a linked list?
What is a constant reference?
Why main function is special in c++?
What is cin clear () in c++?
How does the copy constructor differ from the assignment operator (=)?
What is meant by entry controlled loop? What all C++ loops are exit controlled?