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


Please Help Members By Posting Answers For Below Questions

In which header file does one find isalpha() a) conio.h b) stdio.h c) ctype.h

673


How can I disable the "echo" feature?

604


What are friend classes? What are advantages of using friend classes?

603


What is class definition in c++ ?

625


Are php strings immutable?

558






What is virtual function? Explain with an example

583


How does the copy constructor differ from the assignment operator (=)?

617


Is it possible to write a c++ template to check for a function's existence?

574


What is c++ mutable?

700


Explain bubble sorting.

622


Explain overriding.

602


What is null pointer and void pointer and what is their use?

584


What's the order in which the objects in an array are destructed?

850


Can a program run without main?

622


What is protected inheritance?

592