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
Differentiate between an inspector and a mutator ?
Would you rather wait for quicksort, linear search, or bubble sort on a 200000 element array? (Or go to lunch...) a) Quicksort b) Linear Search c) Bubble Sort
A mXn matrix is given and rows and column are sorted as shown below.Write a function that search a desired entered no in the matrix .with minimum complexity 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
What is anonymous object in c++?
What is a loop? What are different types of loops in c++?
How many ways can a variable be initialized into in C++?
What are the two main components of c++?
How delete [] is different from delete?
What causes a runtime error c++?
write a program that reads in a file and counts the number of lines, words, and characters. Your program should ask the user to input a filename. Open the file and report an error if the file does not exist or cannot be opened for some other reason. Then read in the contents of the file and count the number of lines, words, and characters in the file. Also print additional information about the file, such as the longest and shortest words, and longest and shortest lines. For simplicity, we define a word to be one or more characters ending with white space (a space, tab, carriage return, etc.). Functions for checking the types of characters can be found in the ctype.h header file, so you want to include this header file in your program. For example, the sentence below could be all that is in a file. This sentence IT 104 is taught in C++. has 32 characters, one line, and six words. The shortest line is 32 characters. The longest line is 32 characters. The shortest word is 2 characters. The longest word is 6 characters
What is command line arguments in C++? What are its uses? Where we have to use this?
What is ofstream c++?
Are iterators pointers?
What is the difference between the indirection operator and the address of oper-ator?
Give 10 points of differences between C & C++.