Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Vector Operations in Practice | Containers
C++ STL Containers and Algorithms

bookChallenge: Vector Operations in Practice

Task

Swipe to start coding

Implement two functions:

  • Define a function named createSequence that takes an integer argument n and returns a std::vector<int> containing the numbers from 1 to n (inclusive), in order;
  • Define a function named sumVector that takes a const std::vector<int>& as an argument and returns the sum of its elements as an integer.

Solution

solution.cpp

solution.cpp

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain this in simpler terms?

Can you give me an example?

What are the main benefits or drawbacks?

close

Awesome!

Completion rate improved to 6.67

bookChallenge: Vector Operations in Practice

Swipe to show menu

Task

Swipe to start coding

Implement two functions:

  • Define a function named createSequence that takes an integer argument n and returns a std::vector<int> containing the numbers from 1 to n (inclusive), in order;
  • Define a function named sumVector that takes a const std::vector<int>& as an argument and returns the sum of its elements as an integer.

Solution

solution.cpp

solution.cpp

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 2
single

single

some-alt