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
When does the c++ compiler create temporary variables?
What are destructors?
What is the this pointer?
What is const in c++?
What is the difference between global int and static int declaration?
What does count ++ do in c++?
Which one is better- macro or function?
What is c++ programming language?
Is there a sort function in c++?
Explain one method to process an entire string as one unit?
What is the main purpose of c++?
Can a function take variable length arguments, if yes, how?
What is the difference between #import and #include?
Comment on c++ standard exceptions?
What is abstraction c++?