1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
int main()
{
const unsigned int N = 3;
unsigned int st_grades[][N] =
{
{ 20, 30, 40 },
{ 40, 50, 60 },
{ 60, 70, 80 }
};
unsigned int sum[N];
std::transform( std::begin( st_grades ), std::end( st_grades ), std::begin( sum ),
[]( unsigned int ( &a )[N] )
{ return ( std::accumulate( std::begin( a ), std::end( a ), 0u ) ); } );
std::transform( std::begin( sum ), std::end( sum ),
std::ostream_iterator<unsigned int>( std::cout, " " ),
[]( unsigned int x ) { return ( x / N ); } );
return 0;
}
|