erehh

3-ის ჯერადების რაოდენობა 100 ელემენტიანი ვექტორიდან

Dec 16th, 2021
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. //3-ის ჯერადების რაოდენობა 100 ელემენტიანი ვექტორიდან.
  2. #include <iostream>
  3. #include <vector>
  4. #include <ctime>
  5. using namespace std;
  6. bool isMultiple_3(const int);//ბულიონის პროტოტიპი
  7. int Count(const vector<int>, bool f(int));//პროტოტიპი ითვლის 3-ის ჯერადებს
  8. int main()
  9. {
  10.     vector<int> a;
  11.     for (int i = 0; i < 100; ++i)
  12.         a.push_back(rand());
  13.     cout << "3-is jeradebis raodenoba = "
  14.         << Count(a, isMultiple_3) << endl;
  15. }
  16. //ფუნქცია, რომელიც ეძებს 3-ის ჯერადებს
  17. bool isMultiple_3(const int x)
  18. {
  19.     return x % 3 == 0;
  20. }
  21. //ფუნქცია, რომელიც ითვლის 3-ის ჯერადებს
  22. int Count(const vector<int> x, bool f(int))
  23. {
  24.     int counter = 0;
  25.     for (int i = 0; i < x.size(); ++i)
  26.         if (f(x[i])) counter++;
  27.     return counter;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment