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;
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;
Our goal is to make the OpenLab accessible for all users.
Our goal is to make the OpenLab accessible for all users.
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)
Hi Martin. Benjamin is absolutely correct.