This:
sum=(limit*(2*1+(limit-1)*1))/ 2;
actually is the same as this formula:
where Sn
denotes the sum of n
terms, n
is the number of terms(limit
) and a1
is the first term of the AP and d
is the common difference. All this information is found in the Wikipedia page for arithmetic progressions.
solved How the formula of a Arithmetic Progression works? [closed]