Praktikum_mf

Базовые алгоритмы/Алгоритм accumulate/Задание 1

Sep 30th, 2021
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <numeric>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. double Average(const vector<int>& xs) {
  8.     if (xs.empty()) {
  9.         return 0;
  10.     }
  11.  
  12.     return accumulate(xs.begin(), xs.end(), 0.0) / xs.size();
  13. }
  14.  
  15. int main() {
  16.     // не меняйте код main
  17.     cout << Average({1, 2, 2}) << endl;
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment