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
How would you find out if a linked-list is a cycle or not?
What is a friend function in c++?
Explain the difference between overloading and overriding?
Can a constructor be private?
What is stl containers in c++?
Explain the problem with overriding functions
What is a .lib file in c++?
What is the full form of ios?
Who calls main function?
Write a program to interchange 2 variables without using the third one.
What is the difference between passing by reference and passing a reference?
What do you know about near, far and huge pointer?
What are disadvantages of pointers?
If you want to share several functions or variables in several files maitaining the consistency how would you share it?
What are the differences between the function prototype and the function defi-nition?