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 a breakpoint?

1021


In which situation the program terminates before reaching the breakpoint set by the user at the beginning of the mainq method?

1066


What is the difference between strcpy() and strncpy()?

1141


Is multimap sorted c++?

1002


What is virtual function? Explain with an example

1096


Define upcasting.

1034


By using c++ with an example describe linked list?

1022


Is swift a good first language?

1042


What is dev c++ used for?

1033


What is the best c++ book?

1264


Write a program which uses functions like strcmp(), strcpy()? etc

1093


Which c++ operator cannot overload?

1010


What are the advantages of early binding?

1067


In int main(int argc, char *argv[]) what is argv[0] a) The first argument passed into the program b) The program name c) You can't define main like that

1092


What is a syntax in c++?

1157