fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // Prompt user for input
  6. cout << "Enter four integers separated by spaces: ";
  7.  
  8. int a, b, c, d;
  9. cin >> a >> b >> c >> d;
  10.  
  11. // Display entered values (optional for debugging)
  12. cout << "You entered: " << a << " " << b << " " << c << " " << d << endl;
  13.  
  14. // Calculate sum, average, and product
  15. int sum = a + b + c + d;
  16. double average = sum / 4.0; // Use 4.0 to get decimal average
  17. int product = a * b * c * d;
  18.  
  19. // Find the smallest number
  20. int smallest = a;
  21. if (b < smallest) smallest = b;
  22. if (c < smallest) smallest = c;
  23. if (d < smallest) smallest = d;
  24.  
  25. // Find the largest number
  26. int largest = a;
  27. if (b > largest) largest = b;
  28. if (c > largest) largest = c;
  29. if (d > largest) largest = d;
  30.  
  31. // Output the results
  32. cout << "Sum: " << sum << endl;
  33. cout << "Average: " << average << endl;
  34. cout << "Product: " << product << endl;
  35. cout << "Smallest: " << smallest << endl;
  36. cout << "Largest: " << largest << endl;
  37.  
  38. // Check even or odd for each number
  39. cout << a << " is " << (a % 2 == 0 ? "even" : "odd") << endl;
  40. cout << b << " is " << (b % 2 == 0 ? "even" : "odd") << endl;
  41. cout << c << " is " << (c % 2 == 0 ? "even" : "odd") << endl;
  42. cout << d << " is " << (d % 2 == 0 ? "even" : "odd") << endl;
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.01s 5316KB
stdin
45
stdout
Enter four integers separated by spaces: You entered: 45 21998 -1274475744 5293
Sum: -1274448408
Average: -3.18612e+08
Product: 699276736
Smallest: -1274475744
Largest: 21998
45 is odd
21998 is even
-1274475744 is even
5293 is odd