User Tools

Site Tools


c:c_inner_product_with_predicate

C - C++ Inner Product with Predicate

#include <algorithm>
#include <iostream>
#include <functional>
#include <numeric>
using namespace std;
 
int main()
{
  const int N = 5;
  int x1[N], x2[N];
 
  for (int i = 0; i < N; ++i) {
    x1[i] = i + 1;
    x2[i] = i + 2;
  }
 
  // compute "inner product," with roles of + and * reversed:
  int result = inner_product(&x1[0], &x1[N], &x2[0], 1,multiplies<int>(), plus<int>());
 
  cout << "Inner product with roles of + and * reversed: " << result << endl;
 
  return 0;
}
c/c_inner_product_with_predicate.txt · Last modified: 2020/07/15 10:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki