An arithmetic progression is a series in which each successive term is generated by adding the term before it to a fixed value called the common difference. Given the first term of an arithmetic progression $a$, and a common difference (the difference between each consecutive term) $d$, the $nth$ term is:
$$ \begin{equation}\begin{aligned} u_n=a+(n-1)d\\ \end{aligned}\end{equation} $$The sum up to the $nth$ term is: $$ \begin{equation}\begin{aligned} S_n=\frac{n}{2}[2a+(n-1)d]\\ \end{aligned}\end{equation} $$
Deriving the formula for the sum of the first $n$ terms in an AP
Consider that the sum up to the $nth$ term is: $$ \begin{equation}\begin{aligned} S_n&=u_1+u_2+...+u_{n-1}+u_n\\ &=[a]+[a+d]+...+[a+(n-2)d]+[a+(n-1)d]\\ \end{aligned}\end{equation} $$
Reversing this series we get: $$ \begin{equation}\begin{aligned} S_n&=u_n+u_{n-1}+...+u_2+u_1\\ &=[a+(n-1)d]+[a+(n-2)d]+...+[a+d]+[a]\\ \end{aligned}\end{equation} $$
Adding these two: $$ \begin{equation}\begin{aligned} S_n+S_n&=[a+a+(n-1)d]+[a+d+a+(n-2)d]+...+[a+(n-2)d+a+d]+[a+(n-1)d+a]\\ 2S_n&=[2a+(n-1)d]+[2a+(n-1)d]+...+[2a+(n-1)d]+[2a+(n-1)d]\\ 2S_n&=n[2a+(n-1)d]\\ \therefore S_n&=\frac{n}{2}[2a+(n-1)d]\\ \end{aligned}\end{equation} $$
Example: Find the sum of the first $100$ even numbers starting at $0$.
Example: Find the sum of the first $50$ odd numbers starting at $1$.
Example: Find the first term and common difference of an arithmetic progression in which the $7th$ term is $-14$ and the $9th$ term is $4$ times the $4th$ term. (Answer: $a=4$, $d=-3$)
Example: An arithmetic progression has the $8th$ term as $30$ and the sum up to the $6th$ term is $9$ times the sum up to the $2nd$ term. (Answer: $a=2$, $d=4$)
Example: Find the first term and common difference for an AP where the sum up to the $7th$ term is $-98$ and the sum up to the $6th$ term is $\frac{23}{4}$ times the sum up to the $3rd$ term. (Answer: $a=1$, $d=-5$)
Code to generate an arithmetic progression
The following is Golang code to generate an AP given the first term and common difference:
package main
import "fmt"
func main() {
var a int
var d int
AcceptFirstTerm:
fmt.Println("Please enter the first term:")
_, err := fmt.Scanf("%d", &a)
if err != nil {
fmt.Println("Error reading 'a':", err)
goto AcceptFirstTerm
}
AcceptCommonDifference:
fmt.Println("Please enter the common difference:")
_, err = fmt.Scanf("%d", &d)
if err != nil {
fmt.Println("Error reading 'd':", err)
goto AcceptCommonDifference
}
sum := 0
for n := 1; n <= 10; n++ {
u_n := a + (n-1)*d
sum += u_n
fmt.Printf("u_%d = %d, S_%d = %d\n", n, u_n, n, sum)
}
}
Run the program:
go run arithmetic-progression.go