How to find the first element that divide by N in vector using C++

1 Answer

0 votes
#include <iostream>
#include <vector>
#include <algorithm>

using std::cout;
using std::endl;

int main()
{
	std::vector<int> vec = { 3, 1, 4, 2, 5, 8, 6, 9 };
	std::vector<int>::iterator pos;

	pos = std::find_if(vec.begin(), vec.end(), [](int element) { return element % 2 == 0; });

	cout << *pos << endl;

	return 0;
}

/*
run:

4

*/

 



answered Feb 21, 2018 by avibootz
edited Feb 21, 2018 by avibootz
...