C++ vector Create a Vector of Integers Question

Introduction

Write a program that defines a vector of integers.

Use the std::count_if function and a user-provided lambda function to count only even numbers.

You can use the following code structure:

#include <iostream> 

int main() 
{ 

} 


#include <iostream> 
#include <vector> 
#include <algorithm> 

int main() 
{ 
    std::vector<int> v = { 5, 10, 4, 1, 3, 8 }; 
     int mycount = std::count_if(std::begin(v), std::end(v), [](int x)  
     {return x % 2 == 0; }); 
    std::cout << "The number of even numbers is: " << mycount; 
} 



PreviousNext

Related