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 purpose of ios::basefield in the following statement?

1198


Is c++ primer good for beginners?

989


What is the basic concept of c++?

960


Explain the use of vtable.

1028


Can I learn c++ without learning c?

942


What is a map in c++?

1100


What is the use of object in c++?

1049


What is the best c++ compiler?

1060


Describe the role of the c++ in the tradeoff of safety vs. Usability?

1160


Is the declaration of a class its interface or its implementation?

1121


How many namespaces are there in c++?

1010


Evaluate the following expression as C++ would do :8 * 9 + 2 * 5 a) 82 b) 79 c) 370 d) list

950


Is it possible to provide default values while overloading a binary operator?

1209


Is turbo c++ free?

1015


Give an example of run-time polymorphism/virtual functions.

948