Bifalgorithm post · Computer science one · Summation
How do you compute a summation with a for loop in C?
How do you compute a summation with a for loop in C? (Computer science one · Summation) — "Let’s revisit the example from Section 4.2.1 in which we computed th…
Ideas in this flowchart
- Summation of integers with a for loop in C
- The example computes 1 + 2 + · · · + 10
- Code Sample 17.6 implements the summation
- The variable i is declared as an integer
- The variable sum is initialized to 0
- The for loop starts at 1, continues while i ≤ 10, and increments i
- Each iteration adds i to sum
- The code can be generalized to sum up to a variable n
- The generalized for loop uses n as its upper bound