Answer to Question #100773 in C++ for zahra

Question #100773
Write aprogram that asks the user to enter an array of random numbers,then sort the numbers
(ascendingorder),then print the new array,after that asks the user for a new two numbers and add
them to the same array and keep the array organization.
1
Expert's answer
2019-12-26T04:16:50-0500

#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;


int main()

{

int n = 20, t;

cout << "How many numbers you want to input > ";

cin >> n;

vector<int> arr(n);

cout << "Enter " << n << " number\n";

for(int i=0; i<n; cin >> arr[i++]);

sort(arr.begin(), arr.end());

for(int i=0; i<n; cout << arr[i++] << " ");

cout << endl;

cout << "Enter new two numbers\n";

cin >> t;

arr.push_back(t);

cin >> t;

arr.push_back(t);

sort(arr.begin(), arr.end());

for(size_t i=0; i<arr.size(); cout << arr[i++] << " ");

cout << endl;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Zahra
26.12.19, 12:08

Write a program that will display all numbers multiple of 7 which are between 1 and 100 and o display the cumulative sum as well as the final sum

Assignment Expert
26.12.19, 12:07

Dear Zahra, Questions in this section are answered for free. We can't fulfill them all and there is no guarantee of answering certain question but we are doing our best. And if answer is published it means it was attentively checked by experts. You can try it yourself by publishing your question. Although if you have serious assignment that requires large amount of work and hence cannot be done for free you can submit it as assignment and our experts will surely assist you.

Zahra
26.12.19, 12:00

Write a program that asks the user to enter an array of random numbers,then sort the numbers (ascending order),then print the new array,after that asks the user for a new two numbers and add them to the same array and keep the array organization. solve with do-while

Zahra
26.12.19, 11:57

Write a program that will find the inverse of any two dimensional array without the usage of the built-in function. solve with do_while

Zahra
26.12.19, 11:50

Write a program that asks the user to enter integer numbers and store the numbers in a two dimensional array,then replace any 9 digit by 0 digit. After that replace the numbers with the odd summations indices by the even summation indices.solve while loop

Zahra
26.12.19, 11:42

Write a code that will calculate randomly a number between 1 and 10 (without displaying it) and will ask the user to guess it.If the user answers correctly,the program prints“Good”and add 1 to his score, if not,the program prints“sorry”,gives the correct answer, then selects another number.After 10 consecutive games, the programs stops and prints the final score. Hint: use a random builtin function (rand) and write the #include at the beginning.

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS