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

bookChallenge: Generate and Transform Sequence

Uppgift

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 allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 6
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

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

Svep för att visa menyn

Uppgift

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 desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 6
single

single

some-alt