Beispiellösung

Content

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <random>
#include <vector>

int main() {
   /* initialize values and fill it with shuffled values 1..100 */
   std::vector<int> values(100);
   std::iota(values.begin(), values.end(), 1);
   std::shuffle(values.begin(), values.end(), std::mt19937(2));

   /* select all even values out of it */
   std::vector<int> selected_values;
   std::copy_if(values.begin(), values.end(),
      std::back_inserter(selected_values),
      [](int value) { return value % 2 == 0; });

   /* print selected values */
   int count = 0;
   for (auto value: selected_values) {
      std::cout << std::setw(4) << value;
      if (++count % 10 == 0) std::cout << std::endl;
   }
}
theon$ g++ -Wall -o select-even3 select-even3.cpp
theon$ ./select-even3
   6  20  18  88  48  70  90  54  56  64
  42  76  52  96  60  58  34   2  98  66
  46   8  10  26  14  86   4  32  92  84
  62  50  36  74  16  38  72  30  24  82
  68  22  28  78  94  44 100  12  80  40
theon$