fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main() {
  5. // Define a vector to store the 6 numbers
  6. std::vector<int> numbers(6);
  7.  
  8. // Prompt the user to enter the numbers
  9. std::cout << "Enter 6 numbers:\n";
  10. for (int i = 0; i < 6; ++i) {
  11. std::cin >> numbers[i];
  12. }
  13.  
  14. // Initialize maxProduct to the product of the first two numbers
  15. int maxProduct = numbers[0] * numbers[1];
  16.  
  17. // Iterate through pairs of numbers and update maxProduct if a larger product is found
  18. for (int i = 0; i < 5; ++i) {
  19. for (int j = i + 1; j < 6; ++j) {
  20. int product = numbers[i] * numbers[j];
  21. if (product > maxProduct) {
  22. maxProduct = product;
  23. }
  24. }
  25. }
  26.  
  27. // Output the largest product
  28. std::cout << "The largest product of pairs is: " << maxProduct << std::endl;
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
Enter 6 numbers:
The largest product of pairs is: 0