fork download
  1. #include <iostream>
  2. #include <random>
  3. #include <vector>
  4. #include <functional>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. vector<int> tab(99);
  11. int sum = 0;
  12.  
  13. random_device rd;
  14. auto rand = bind(uniform_int_distribution<>(4, 10), mt19937(rd()));
  15.  
  16. generate(tab.begin(), tab.end(), rand);
  17. for_each(tab.cbegin(), tab.cend(), [&sum](int num) { sum += num; cout << num << "\n"; });
  18. cout << "Suma: " << sum << "\n";
  19. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
5
4
10
4
4
5
9
8
7
10
9
6
4
8
10
10
8
9
5
9
6
10
7
9
5
6
10
10
5
9
5
10
7
4
6
9
10
7
4
7
6
9
4
4
8
7
8
6
5
10
5
8
4
4
6
9
7
10
5
6
4
4
7
6
10
7
4
9
8
5
4
6
7
7
8
7
6
10
8
4
5
9
4
9
6
5
9
4
7
10
4
8
4
7
9
9
9
4
8
Suma: 682