write a program to insert an element into an array
Answer Posted / harini
#include<iostream>
#include<conio.h>
main()
{
int a[5],b,n,e,i,j;
std::cout<<"enter the no of elements:";
std::cin>>n;
std::cout<<"enter the array elements:";
for(i=0;i<n;i++)
{
std::cin>>a[i];
}
std::cout<<"enter the position of insertion:";
std::cin>>b;
std::cout<<"enter the element to be inserted:";
std::cin>>e;
for(j=n;j>b;j--)
{
a[j]=a[j-1];
}
a[j]=e;
std::cout<<"the new array elements are:\n";
for(j=0;j<=n;j++)
{
std::cout<<a[j]<<"\n";
}
getch();
}
| Is This Answer Correct ? | 5 Yes | 2 No |
Post New Answer View All Answers
Is it possible for the objects to read and write themselves?
What are function prototypes?
What is istream and ostream in c++?
Can I run c program in turbo c++?
Explain the virtual inheritance in c++.
Write a program to show polymorphism in C++?
Distinguish between new and malloc and delete and free().
What are virtual functions in c++?
What is the most useful programming language?
Can char be a number c++?
How do you remove an element from a set in c++?
What do the keywords volatile and mean mutable?
How much maximum can you allocate in a single call to malloc()?
What do you mean by ‘void’ return type?
Why is c++ not purely object oriented?