#include #include #include int main() { const int SIZE = 4; int arr[SIZE][SIZE] = { {2, 4, 6, 8}, {10, 12, 14, 16}, {18, 19, 20, 22}, {24, 26, 28, 30} }; std::vector numbers; int n; // Extract numbers from the array and store them in a vector for (int i = 0; i < SIZE; ++i) { for (int j = 0; j < SIZE; ++j) { numbers.push_back(arr[i][j]); } } // Sort the numbers in descending order std::sort(numbers.begin(), numbers.end(), std::greater()); std::cout << "Enter the number of largest numbers to output: "; std::cin >> n; // Validate the input for 'n' if (n > numbers.size()) { std::cout << "There are only " << numbers.size() << " numbers in the array.\n"; n = numbers.size(); } // Output the largest numbers from the array std::vector largestNumbers(numbers.begin(), numbers.begin() + n); // Output the user's numbers std::vector userNumbers(n); std::cout << "Enter " << n << " numbers: "; for (int i = 0; i < n; ++i) { std::cin >> userNumbers[i]; } // Combine largest numbers and user input largestNumbers.insert(largestNumbers.end(), userNumbers.begin(), userNumbers.end()); // Sort the combined result in descending order std::sort(largestNumbers.begin(), largestNumbers.end(), std::greater()); // Output the final sorted array std::cout << "Combined output in descending order: "; for (int num : largestNumbers) { std::cout << num << " "; } std::cout << std::endl; return 0; }