write a program to insert an element into an array

Answer Posted / anupriya garg

#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 ?    17 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain bubble sorting.

723


What is singleton class in c++?

689


What do you mean by const correctness?

715


State the difference between delete and delete[].

684


What is the main purpose of c++?

645






What are compilers in c++?

700


Which c++ operator cannot overload?

641


Explain Memory Allocation in C/C++ ?

716


Can you declare an array without a size in c++?

670


Write a struct time where integer m, h, s are its members?

607


What are references in c++? What is a local reference?

668


Is C++ case sensitive a) False b) Depends on implementation c) True

694


What are register variables?

730


How to tokenize a string in c++?

691


How can you differentiate between inheritance and implementation in c++?

734