Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Cumulative Sum | For Loop
C Loops for Beginners

bookChallenge: 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 cumulativeSum that takes an integer n as its parameter;
  • Use a for loop to add all numbers from 1 to n and 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?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 3
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

close

bookChallenge: 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 cumulativeSum that takes an integer n as its parameter;
  • Use a for loop to add all numbers from 1 to n and 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

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 2. Kapitel 3
single

single

some-alt