fork download
  1. #include <iostream>
  2. #include <numeric>
  3. #include <vector>
  4.  
  5. int main() {
  6. std::vector<int> numbers(10);
  7. std::iota(std::begin(numbers), std::end(numbers), 1);
  8.  
  9. int Z = 2;
  10. int A = 4;
  11. int B = 7;
  12.  
  13. int prod = 1;
  14. int count = 0;
  15.  
  16. for (size_t i = 0, size = numbers.size(); i < size; ++i) {
  17. int n = numbers[i];
  18. if (n != Z) {
  19. prod *= n;
  20. }
  21. if (i % 2 && n > A && n <= B) {
  22. ++count;
  23. }
  24. }
  25.  
  26. std::cout << "Product of numbers not equal to Z: " << prod
  27. << "\nCount of numbers in (A, B] at odd positions: " << count;
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 5348KB
stdin
Standard input is empty
stdout
Product of numbers not equal to Z: 1814400
Count of numbers in (A, B] at odd positions: 1