Using the generic accumulate algorithm to compute a product by using multiplies : multiply « STL Algorithms Helper « C++






Using the generic accumulate algorithm to compute a product by using multiplies

 
 

#include <iostream>
#include <vector>
#include <cassert>
#include <numeric>  // For accumulate
#include <functional>  // For multiplies
using namespace std; 

int main()
{
  int x[5] = {2, 3, 5, 7, 11};

  vector<int> vector1(&x[0], &x[5]); 
  
  int product = accumulate(vector1.begin(), vector1.end(),1, multiplies<int>());
    
  cout << product << endl;
  return 0;
}
/* 
2310

 */
        
  








Related examples in the same category

1.Using the generic accumulate algorithm to compute a product by using a function object