68 719
Assignments Done
Successfully Done
In January 2019

Answer to Question #71583 in C++ for m

Question #71583
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.
using while,for and array if possible
Expert's answer
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void printArray(const vector<int>& v)
cout << "Content of the array: \n";
for (const auto& n : v)
cout << n << " ";
cout << '\n';

int main()
cout << "Enter the number of elements in array: ";
int size;
cin >> size;
vector<int>v(size), copy(size+2);
cout << "Please enter the elements: ";
for (int i = 0; i < size; ++i)
cin >> v[i];
copy[i] = v[i];

cout << "Original array: \n";

sort(v.begin(), v.end());
cout << "Sorted original array: \n";

cout << "Please enter two more numbers to the array: ";
for (int i = 0; i < 2; ++i)
cin >> copy[size + i];

cout << "Extended original array: \n";

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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions