inner_product( ) produces a summation of the product of corresponding elements in two sequences and returns the result. : inner_product « STL Algorithms Helper « C++






inner_product( ) produces a summation of the product of corresponding elements in two sequences and returns the result.

  
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
   
int main()
{
  vector<int> v1(5), v2(5);
  int i, total;
   
  for(i=0; i<5; i++) 
     v1[i] = i;
  for(i=0; i<5; i++) 
     v2[i] = i+2;
   
  total = inner_product(v1.begin(), v1.end(),v2.begin(), 0);
   
  cout << total;
   
  return 0;
}
  
    
  








Related examples in the same category

1.Use inner_product to process sum of all products(0 + 1*1 + 2*2 + 3*3 + 4*4 + 5*5 + 6*6)
2.Use inner_product to calculate inner reverse product
3.Use inner_product with inner and outer operation
4.Compute the sample standard deviation