Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Traverse and Sum Elements | Iterator Fundamentals
Practice
Projects
Quizzes & Challenges
Вікторини
Challenges
/
C++ STL Iterators
Секція 1. Розділ 4
single

single

bookChallenge: Traverse and Sum Elements

Свайпніть щоб показати меню

Завдання

Swipe to start coding

Write a function that traverses a container using iterators and returns the sum of all elements.

  • The function signature must be int sum_elements(const std::list<int>& numbers);.
  • Start iteration at numbers.begin() and stop when the iterator equals numbers.end().
  • Use ++it to move the iterator forward.
  • Only dereference the iterator when it != numbers.end().
  • Do not use size(), empty(), or indices.
  • Do not use ranged-for loops or algorithms like std::accumulate.
  • The function should return the sum of all elements in the list.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 4
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt