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

bookChallenge: Generate and Transform Sequence

Task

Swipe to start coding

Implement two functions:

  • generateSequence: takes an integer n and returns a std::vector<int> of size n filled with random values. Use std::generate to fill the vector. Generate random integers between 1 and 100 (inclusive).
  • squareElements: takes a const std::vector<int>& and returns a new vector where each element is the square of the corresponding input value. Use std::transform for this operation.

Solution

solution.cpp

solution.cpp

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 6
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?

What are the main takeaways from this?

Can you give me a real-world example?

close

Awesome!

Completion rate improved to 6.67

bookChallenge: Generate and Transform Sequence

Swipe to show menu

Task

Swipe to start coding

Implement two functions:

  • generateSequence: takes an integer n and returns a std::vector<int> of size n filled with random values. Use std::generate to fill the vector. Generate random integers between 1 and 100 (inclusive).
  • squareElements: takes a const std::vector<int>& and returns a new vector where each element is the square of the corresponding input value. Use std::transform for this operation.

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Β 3. ChapterΒ 6
single

single

some-alt