Untitled

mail@pastecode.io avatar
unknown
c_cpp
3 days ago
559 B
0
Indexable
Never
#include <iostream>
#include <vector>

std::vector< int > getEvenNumbers( const std::vector< int >& v )
{
    std::vector< int > result;

    for( const auto& e : v )
    {
        if( e % 2 == 0 )
        {
            result.push_back( e );
        }
    }

    return result;
}

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

    auto evenVector = getEvenNumbers( vec );

    for( const auto& e : evenVector )
    {
        std::cout << e << ", ";
    }
    std::cout << "\n\n";

    return 0;
}
Leave a Comment