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
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"; printArray(v);
sort(v.begin(), v.end()); cout << "Sorted original array: \n"; printArray(v);
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"; printArray(copy); }
Comments
Leave a comment