Question: Please write in C++ Given a list of random integers, find and print out all the values that are prime. It is possible that there

Please write in C++

Given a list of random integers, find and print out all the values that are prime. It is possible that there are none. There are no restrictions on for-loops this time.

Starter Code:

#include  #include  #include  #include  #include  #include  #include  static int getRandomNumber(); template std::ostream& operator<<(std::ostream& out, std::vector list) { out << "["; for (const auto& val : list) { out << val << ", "; } out << "]"; return out; } int main() { std::vector list; std::generate_n(std::back_inserter(list), 20, []() { return getRandomNumber(); }); std::cout << list << " "; // TODO: find and print out the first prime number in the list } static int getRandomNumber() { static std::mt19937 rng{ std::random_device{}() }; static std::uniform_int_distribution rand{ 2, 100 }; return rand(rng); } 

Sample Output:

[86, 91, 83, 58, 4, 12, 43, 86, 88, 76, 20, 93, 19, 78, 28, 15, 32, 97, 72, 90, ] 83 43 19 97

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!