1 2 3 4 5 6 7 8 9 10 11 12
|
int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int b[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1 };
int sum = std::inner_product( std::begin( a ), std::end( a ), std::begin( b ), 0,
std::plus<int>(), std::plus<int>() );
std::cout << "sum = " << sum << std::endl;
sum = std::accumulate( std::begin( a ), std::end( a ),
std::accumulate( std::begin( b ), std::end( b ), 0 ) );
std::cout << "sum = " << sum << std::endl;
|