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

bookChallenge: Generate and Transform Sequence

Opgave

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.

Løsning

solution.cpp

solution.cpp

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 6
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores 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

Stryg for at vise menuen

Opgave

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.

Løsning

solution.cpp

solution.cpp

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 6
single

single

some-alt