Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

write a program to insert an element into an array

Answer Posted / prasoon

#include<iostream.h>
#include<conio.h>
void main()
{
int *p,n,item,pos;
clrscr();
cout<<"\nEnter the number of elements in the array: ";
cin>>n;
p=new int[n+1];
cout<<"\nEnter the elements: \n";
for(int i=0;i<n;i++)
cin>>p[i];
cout<<"\nThe entered elements are: \n\n";
for(i=0;i<n;i++)
cout<<p[i]<<"\t";
cout<<"\nEnter the item to be inserted: ";
cin>>item;
cout<<"\nEnter its position: ";
cin>>pos;
for(i=n;i>=pos;i--)
p[i]=p[i-1];
p[pos-1]=item;
n++;
cout.flush();
cout<<"\nThe modified array is:\n\n";
for(i=0;i<n;i++)
cout<<p[i]<<"\t";
delete p;
getch();
}

Is This Answer Correct ?    162 Yes 51 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the output of the following program? Why?

1106


What do you mean by “this” pointer?

1046


What is the difference between C and CPP?

1122


What is flush () in c++?

1042


Do you know the problem with overriding functions?

1050


What are inline functions? What is the syntax for defining an inline function?

1106


What is a static element?

1031


Where is atoi defined?

1083


what are the iterator and generic algorithms.

2111


What is the use of namespace std in C++?

1033


Explain how the virtual base class is different from the conventional base classes of the opps.

1120


When the constructor of a base class calls a virtual function, why doesn't the override function of the derived class gets called?

1064


Why do we need pointers?

962


Explain overriding.

956


What is oops in c++?

1011