fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <limits>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. int n, sum = 0, count = 0, product = 1, max_negative = numeric_limits<int>::min();
  9. bool has_odd = false, has_negative = false;
  10.  
  11. cout << "Введите количество чисел: ";
  12. cin >> n;
  13.  
  14. vector<int> numbers(n);
  15. cout << "Введите последовательность:\n";
  16. for (int i = 0; i < n; i++) {
  17. cin >> numbers[i];
  18.  
  19. if ((i + 1) % 2 == 0 && numbers[i] % 2 != 0) {
  20. sum += numbers[i];
  21. count++;
  22. }
  23.  
  24. if (numbers[i] % 2 != 0) {
  25. product *= numbers[i];
  26. has_odd = true;
  27. }
  28.  
  29. if (numbers[i] < 0 && numbers[i] > max_negative) {
  30. max_negative = numbers[i];
  31. has_negative = true;
  32. }
  33. }
  34.  
  35. if (!has_odd) product = 0;
  36. int difference = has_negative ? product - max_negative : product;
  37.  
  38. cout << "Сумма: " << sum << "\nКоличество: " << count << "\nРазность: " << difference << endl;
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Введите количество чисел: Введите последовательность:
Сумма: 0
Количество: 0
Разность: 0