Share
Explore BrainMass

Combinatorial Techniques : What is the algorithm for computing the sum of an arithmetic progression of n terms with first term a and common difference d?

What is the algorithm for computing the sum of an arithmetic progression of n terms with first term a and common difference d?

--------------
Step 1 Set S = a, k = 1, and t = a.
Step 2 while k < n
(a) Replace t with t + d
(b) Replace S with S + 1
(b) Replace k with k + 1
endwhile
Setp 3 Print S.

How did you determine this? Need tutoring help so I can learn how to answer additional ones. Thanks and Happy New Year!

Solution Preview

As far as I understand it, you wanted an algorithm for a function that will accept *variables*, which are a (the first term), d (the difference between consecutive terms) and n (number of terms).
Thu function should return a single number "Sum" which is the sum of all the terms in the series.

First, note that the algorithm that you provided in the question is completely wrong. Replacing S with S+1 simply raises the sum accumulator by 1, which is obviously wrong if the difference between consecutive terms is more ...

$2.19