inrprod2.cpp
inrprod2.cpp
#include ‹stl.h›
#include ‹iostream.h›
#include ‹string.h›
int add(int a_, int b_) {
return a_ + b_;
}
int mult(int a_, int b_) {
return a_ * b_;
}
int main() {
vector‹int› v1(3);
vector‹int› v2(v1.size());
for (int i = 0; i ‹ v1.size(); i++) {
v1[i] = i + 1;
v2[i] = v1.size() - i;
}
ostream_iterator‹int› iter(cout, " ");
cout ‹‹ "Inner product(product of sums): ";
copy(v1.begin(), v1.end(), iter);
cout ‹‹ " ";
copy(v2.begin(), v2.end(), iter);
int result = inner_product(v1.begin(), v1.end(), v2.begin(), 1, mult, add);
cout ‹‹ " is: " ‹‹ result ‹‹ endl;
return 0;
}