Advertisement
Soverein

Untitled

Oct 31st, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 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);//paste of random numbers
  16. cout << "<Vector>::";
  17. for_each(Vector.begin(), Vector.end(), [](int i) {cout << " " << i; });
  18. cout << endl;
  19.  
  20. copy(Vector.begin(), Vector.end(), Vector2.begin());//copy the vector
  21. cout << "<Vector2> ::";
  22. for_each(Vector2.begin(), Vector2.end(), [](int i) {cout << " " << i; });
  23. cout << endl;
  24.  
  25. random_shuffle(Vector2.begin(), Vector2.end());//mix the vector2
  26. cout << "Mix of the <Vector2> ::";
  27. for_each(Vector2.begin(), Vector2.end(), [](int i) {cout << " " << i; });
  28.  
  29. for_each(Vector2.begin(), Vector2.end(), [](int i) {count1 += i; });
  30. int sr;
  31. sr = count1 / n;
  32. cout << "\nmean value = " << sr<<endl;
  33.  
  34. transform(Vector.begin(), Vector.end(), Vector2.begin(),Vector.begin(), multiplies<int>());
  35. cout << "The element-wise products of vectors \n are: ";
  36. for_each(Vector.begin(), Vector.end(), [](int i) {cout << " " << i; });//* elements
  37.  
  38. cout << "\n"<<"square of elements Vector = ";
  39. for_each(Vector.begin(), Vector.end(), [](int& sqr) {sqr = pow(sqr, 2); });
  40. for_each(Vector.begin(), Vector.end(), [](int sqr) {cout << " " << sqr; });// square of elements
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement