Advertisement
chevengur

СПРИНТ №1 | Базовые алгоритмы | Урок 5: Алгоритм accumulate 1/2

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