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
Comment on c++ standard exceptions?
How can you say that a template is better than a base class?
What is ios :: in in c++?
Define 'std'.
How can you quickly find the number of elements stored in a dynamic array?
How would you implement a substr() function that extracts a sub string from a given string?
What is double in c++?
Describe protected access specifiers?
Explain what are accessor methods?
What is the use of c++ programming language in real life?
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create
Is linux written in c or c++?
What is c++ good for?
Explain how to initialize a const data member.
What is the type of this pointer in c++?