Test #1 Review

Devise an algorithm that finds the sum of all the integers in a list

procedure sum (a1, a2,…,an:integers)

sum = an

for i to an -1

sum= sum + an

return sum;

This entry was posted in Test #1 Review. Bookmark the permalink.

2 Responses to Test #1 Review

  1. Benjamin Lin says:

    sum = an (this should be sum = a1, unless you planing to start adding the sum at the end of the list)
    for i to an -1(you need to define i as the starting value, and also i think you meant n-1, not an-1 because that means you are subtracting the value of the last integer in the list. )
    sum = sum + an (it should be sum + ai or else you keep adding the last value in the list)

  2. Kate Poirier says:

    Hi Martin. Benjamin is absolutely correct.

Leave a Reply

Your email address will not be published. Required fields are marked *