Bifalgorithm post · Computer science one · Summation

How can a summation loop be generalized to sum up to a variable n?

How can a summation loop be generalized to sum up to a variable n? (Computer science one · Summation) — "Let’s revisit the example from Section 4.2.1 in which…

Ideas in this flowchart

  • Generalizing the code for summing integers
  • The discussion revisits the example from Section 4.2.1
  • The example computes the sum 1 + 2 + · · · + 10
  • The code is presented in Code Sample 28.8
  • The code could be generalized beyond a particular upper limit
  • The original version sums up to a particular number
  • The generalized version sums up to a variable n
  • The for loop is modified to use n as its upper limit
Feed/

How can a summation loop be generalized to sum up to a variable n?

No cover

Channel

Computer science one

1 page

"Let’s revisit the example from Section 4.2.1 in which we computed the sum of integers 1 + 2 + · · · + 10. The code is presented in Code Sample 28.8 We could have easily generalized the code somewhat. Instead of computing a sum up to a particular number, we could have written it to sum up to another variable n, in which case the for loop would instead look like the following."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.