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
What do you mean by function pointer?
What do you mean by persistent and non persistent objects?
What is the importance of mutable keyword?
What are the two types of comments, and how do they differ?
Is c++ still being used?
What is the use of default constructor?
Is empty stack c++?
How long does it take to get good at leetcode?
What is the use of endl?
What is rtti in c++?
Discuss the possibilities related to the termination of a program before entering the mainq method?
What is void pointer in c++ with example?
What is abstraction in c++ with example?
Explain static and dynamic memory allocation with an example each.
What are the basic data types used in c++?