write a program to insert an element into an array
Answer Posted / anupriya garg( sviet)
#include<iostream.h>
void main()
{
int a[60],n,item,pos;
cout<<"enter the no. of elements in array";
cin>>n;
cout<<"enter the elements";
for(int i=0;i<=n;i++)
{
cin>>a[i];
}
for(int i=0;i<=n;i++)
{
cout<<a[i];
}
cout<<"enter the item to be inserted";
cin>>item;
cout<<"enter the position";
cin>>pos;
for(int i=n;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=item;
n=n+1;
cout<<"the modified array is ;\n\n";
for(int i=1;i<=n;i++)
cout<<a[i];
}
| Is This Answer Correct ? | 15 Yes | 9 No |
Post New Answer View All Answers
What are default parameters? How are they evaluated in c++ function?
What is flush programming?
Do you know what are the new features that iso/ansi c++ has added to original c++ specifications?
Do vectors start at 0?
Can non-public members of another instance of the class be retrieved by the method of the same class?
What is purpose of new operator?
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.
What is the need of a destructor?
What is c++ virtual inheritance?
What is the use of 'using' declaration in c++?
Does c++ have arraylist?
Explain the operation of overloading of an assignment operator.
What do you mean by inheritance in c++?
How can you quickly find the number of elements stored in a dynamic array? Why is it difficult to store linked list in an array?
Is swift faster than go?