This post has already been read 1225 times!

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main()
{
    int sum = 0;
    int divisor = 3;
    vector<int> numbers { 1, 2, 3, 4, 5, 10, 15, 20, 25, 35, 45, 50 };
    for_each(numbers.begin(), numbers.end(), [divisor, &sum] (int y)
    {
        if (y % divisor == 0)
        {
            cout << y << endl;
            sum += y;
        }
    });
 
    cout << sum << endl;
}

Comments are closed.

Post Navigation