Challenge: Cumulative Sum
Opgave
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.
Løsning
Var alt klart?
Tak for dine kommentarer!
Sektion 2. Kapitel 3
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Fantastisk!
Completion rate forbedret til 9.09
Challenge: Cumulative Sum
Stryg for at vise menuen
Opgave
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.
Løsning
Var alt klart?
Tak for dine kommentarer!
Sektion 2. Kapitel 3
single