Challenge: Cumulative Sum
Task
Swipe to start coding
Write a function that calculates the cumulative sum of all integers from 1 up to a given positive integer n using a for loop.
- Define a function named
cumulativeSumthat takes an integernas its parameter; - Use a for loop to add all numbers from 1 to
nand store the result; - Return the final sum from the function;
- Do not use any library functions for summation; implement the logic using a for loop only.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 3
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 9.09
Challenge: Cumulative Sum
Swipe to show menu
Task
Swipe to start coding
Write a function that calculates the cumulative sum of all integers from 1 up to a given positive integer n using a for loop.
- Define a function named
cumulativeSumthat takes an integernas its parameter; - Use a for loop to add all numbers from 1 to
nand store the result; - Return the final sum from the function;
- Do not use any library functions for summation; implement the logic using a for loop only.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 3
single