Advertisement
Soverein

Untitled

Sep 26th, 2021
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<random>
  5. using namespace std;
  6. vector<int> Vector(15), Vector2(15);
  7. int n = 15;
  8. int count1 = 0;
  9. int Randaa()
  10. {
  11. return (rand() % 16);
  12. }
  13. int main()
  14. {
  15. generate(Vector.begin(), Vector.end(), Randaa);
  16. for_each(Vector.begin(), Vector.end(), [](int i) {cout << " " << i; });
  17. cout << endl;
  18.  
  19. copy(Vector.begin(), Vector.end(), Vector2.begin());
  20. for_each(Vector2.begin(), Vector2.end(), [](int i) {cout << " " << i; });
  21. cout << endl;
  22.  
  23. random_shuffle(Vector2.begin(), Vector2.end());
  24. for_each(Vector2.begin(), Vector2.end(), [](int i) {cout << " " << i; });
  25.  
  26. for_each(Vector2.begin(), Vector2.end(), [](int i) {count1 += i; });
  27. int sr;
  28. sr = count1 / n;
  29. cout << "\nmean value = " << sr<<endl;
  30.  
  31. transform(Vector.begin(), Vector.end(), Vector2.begin(),Vector.begin(), multiplies<int>());
  32. cout << "The element-wise products of vectors \n are: ";
  33. for_each(Vector.begin(), Vector.end(), [](int i) {cout << " " << i; });
  34.  
  35. cout << "\n"<<"square of elements Vector = ";
  36. for_each(Vector.begin(), Vector.end(), [](int& sqr) {sqr = pow(sqr, 2); });
  37. for_each(Vector.begin(), Vector.end(), [](int sqr) {cout << " " << sqr; });
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement