write a program to insert an element into an array

Answer Posted / awais jamil

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int j,x[6]={1,2,3,4,5};
int i,pos;
cout<<"please enter for position"<<endl;
cin>>pos;
cout<<"enter for number"<<endl;
cin>>j;
for(i=4;i>=pos;i--)
{
x[i]=x[i-1];
}
x[pos]=j;

for(i=0;i<6;i++)
cout<<x[i]<<" ";
getch();
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is #include sstream?

626


What is an adaptor class or wrapper class in c++?

609


What are vectors used for in c++?

626


What is searching?

659


what is the use of void main() in C++ language?

641






What happens when you make call 'delete this;'?

603


Assume studentNames and studentIDs are two parallel arrays of size N that hold student data. Write a pseudocode algorithm that sorts studentIDs array in ascending ID number order such that the two arrays remain parallel.

1721


How can I learn c++ easily?

625


How can I improve my c++ skills?

563


Can member functions be private?

602


What is heap sort in c++?

606


List the issue that the auto_ptr object handles?

613


Explain about Garbage Collector?

651


What does obj stand for?

635


What is #include cstdlib in c++?

664