Challenge: Sum Vector Elements
Task
Swipe to start coding
Write a function that takes a numeric vector and returns the sum of its elements using a for loop.
- Initialize a variable to store the sum as zero.
- Use a for loop to iterate over each element in the input vector.
- Add each element to the sum variable.
- Return the sum variable as the result.
Solution
Everything was clear?
Thanks for your feedback!
Section 2. Chapter 2
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 5.56
Challenge: Sum Vector Elements
Swipe to show menu
Task
Swipe to start coding
Write a function that takes a numeric vector and returns the sum of its elements using a for loop.
- Initialize a variable to store the sum as zero.
- Use a for loop to iterate over each element in the input vector.
- Add each element to the sum variable.
- Return the sum variable as the result.
Solution
Everything was clear?
Thanks for your feedback!
Section 2. Chapter 2
single