Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <numeric>
- using namespace std;
- double Average(const vector<int>& xs) {
- // посчитайте среднее арифметическое: поделите сумму на размер
- // суммирование начните с 0.0 - тогда результат выражения будет вещественным числом
- if(xs.empty()){
- return 0.0;
- }else{
- return accumulate(xs.begin(), xs.end(), 0.0)/xs.size();
- }
- }
- int main() {
- // не меняйте код main
- cout << Average({1, 2, 2}) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment