Summation of a set of numbers
Summation means adding the number, which is given in the series.
Note: Computer can add two numbers at a time and return the sum of two numbers. So for this purpose we assign the variable sum as zero.
sum= sum+a1 (Here a1 is the first number) then we do
sum=sum+a2 (Here the new value of sum contains a1+a2) then
sum=sum+a3 (Here the new value of sum contains a1+a2+a3) and so on
sum=sum+an (Here the new value of sum contains a1+a2+a3+.........+ an )
Algorithm:
Step 1: Start
Step 2: Read n numbers to be summed from the input device (such as keyboard).
Step 3: Initialize the variable sum as zero.
Step 4: Initialize the variable count as one.
Step 5: While count is less than or equal to n, i.e. numbers to be added, repeatedly do: Read the number at position count, i.e. when count is 1 read first number, when count is 2, read second number and so on. Update the current sum by adding to it the number read.
Step 6: Write the sum of nth numbers.
Step 7: Stop.