• C++ Напишите программу, которая запрашивает пять целых чисел и выводит в первой строке сумму первых двух чисел, во второй строке -- сумму первых трёх чисел, в третьей строке -- сумму первых четырёх чисел, в четвёртой строке -- сумму всех пяти чисел.


    Заранее спасибо!

Ответы 2

  • Благодарю!
    • Автор:

      twix47
    • 5 лет назад
    • 0
  • #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;

    }

    answer img
  • Добавить свой ответ

Еще вопросы

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years