Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Challenge: Traverse and Sum Elements | Iterator Fundamentals
Practice
Projects
Quizzes & Challenges
Quiz
Challenges
/
C++ STL Iterators
Sezione 1. Capitolo 4
single

single

bookChallenge: Traverse and Sum Elements

Scorri per mostrare il menu

Compito

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.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 4
single

single

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

some-alt