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.

Expert's answer

#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!

LATEST TUTORIALS
APPROVED BY CLIENTS