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 | Introduction
C++ STL Containers and Algorithms
Sectionย 1. Chapterย 12
single

single

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

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ย 1. Chapterย 12
single

single

Ask AI

expand

Ask AI

ChatGPT

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

some-alt