This repository has been archived on 2023-05-13. You can view files and clone it, but cannot push or open issues or pull requests.
mipt_cpp/term1/seminar04_templates/01_sum_even/main.cpp

19 lines
360 B
C++
Raw Normal View History

2023-02-25 19:34:24 +03:00
#include <iostream>
#include <vector>
using std::cout, std::endl;
int sumEven(const std::vector<int>& v) {
int sum = 0;
size_t s = v.size();
for (int i = 0; i < s; ++i)
if (v[i] % 2 == 0)
sum += v[i];
return sum;
}
int main() {
std::vector<int> v {4, 8, 15, 16, 23, 42};
cout << sumEven(v) << endl;
}