#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 largestNumbers; int n; // Display the input matrix std::cout << "Input 4x4 matrix:\n"; for (int i = 0; i < SIZE; ++i) { for (int j = 0; j < SIZE; ++j) { std::cout << arr[i][j] << " "; } std::cout << std::endl; } // Ask for number of largest numbers to return std::cout << "Enter the number of largest numbers to output: "; std::cin >> n; // Flatten the array into a vector for easy sorting std::vector numbers; for (int i = 0; i < SIZE; ++i) { for (int j = 0; j < SIZE; ++j) { numbers.push_back(arr[i][j]); } } // Sort numbers in descending order std::sort(numbers.begin(), numbers.end(), std::greater()); // Get the largest numbers for (int i = 0; i < n && i < numbers.size(); ++i) { largestNumbers.push_back(numbers[i]); } // Output the largest numbers std::cout << "Largest " << n << " numbers from the array: "; for (int num : largestNumbers) { std::cout << num << " "; } std::cout << std::endl; // Display the user's input numbers std::cout << "Enter " << n << " numbers: "; std::vector userNumbers(n); for (int i = 0; i < n; ++i) { std::cin >> userNumbers[i]; } // Display the user's numbers std::cout << "User entered numbers: "; for (int num : userNumbers) { std::cout << num << " "; } std::cout << std::endl; return 0; }