write a program to insert an element into an array

Answer Posted / simi

void insert(int*,int pos,int num);
void main()
{
int a[10],num,pos,i;
cout<<"Enter number which is to be inserted";
cin>>num;
cout<<"Enter position where no. is to be inserted";
cin>>pos;
insert(a,1,78);
insert(a,2,3);
getch();
}
void insert(int *a,int pos,int num)
{
int i;
for(i=9;i>=pos;i--)
{
a[i]=a[i-1];
}
a[i]=num;
}

Is This Answer Correct ?    2 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between global variables and local variable

540


What is object in c++ example?

627


Will a C compiler always compile C++ code a) Yes b) No c) Only optimized compilers

617


Can a new be used in place of old mallocq? If yes, why?

639


what Is DCS ? what i will get benefit when i did?

1838






What are the advantages of using typedef in a program?

643


What are references in c++?

665


Explain how we implement exception handling in c++?

580


What is a type library?

686


What is rvalue?

682


What is function overloading c++?

572


What is token c++?

586


A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9 percent of their gross sales for that week. For example, a saleperson who sells $5000 worth of merchandise in a week receives $200 plus 9 percent of $5000, or a total of $650. You have been supplied with a list of items sold by each salesperson. The values of these items are as follows: Item Value A 239.99 B 129.75 C 99.95 D 350.89 Write a program that inputs one salesperson's items sold in a week (how many of item A? of item B? etc.) and calculates and displays that salesperson's earnings for that week.

3415


How long it will take to learn c++?

618


Explain virtual class and friend class.

605