#include <array>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
int main()
{
std::array<int, 5> arr;
std::generate(arr.begin(), arr.end(), []()
{
return 1 + std::rand() % 100;
});
std::copy(arr.begin(), arr.end(),
std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl << std::accumulate(arr.begin(), arr.end()-3, 0) << std::endl;
std::cout << std::accumulate(arr.begin(), arr.end()-2, 0) << std::endl;
std::cout << std::accumulate(arr.begin(), arr.end()-1, 0) << std::endl;
std::cout << std::accumulate(arr.begin(), arr.end(), 0) << std::endl;
}
9.png
Vrode tak
Объяснение:
/+--+-++