Generation

generate functionFri, 20 Jan 2023

Given an array of numbers with N elements. Rewrite even numbers in a new array and find the product of negative ones in it

#include <iostream> #include <vector> #include <algorithm> #include <numeric> int main() { std::vector<int> numbers {1, 2, 3, -4, -5, -6, 7, 8, 9, 10}; std::vector<int> result; std::copy_if(numbers.begin(), numbers.end(), std::back_inserter(result), [](int x) { return x % 2 == 0; }); int result2 = std::accumulate(result.begin(), result.end(), 1, std::multiplies<int>()); std::cout << result2; }

Want to kickstart your project?Use the new AI Studio to create your code