Both of these formulas are obtained in the same way as in Example 1: Multiply by `r` and subtract.
If `S = 1 + r + cdots + r^n`, then `rS = r + r^2 + cdots + r^n + r^(n+1)`.
Subtracting, we have `S - rS = 1 - r^(n+1)` or `text[(]1 - rtext[)]S = 1 - r^(n+1)`.
Dividing by `1-r`, we obtain `S = (1 - r^(n+1))/(1-r)`.
If `S = r^m + r^(m+1) + cdots + r^n`, then `rS = r^(m+1) + r^(m+2) + cdots + r^n + r^(n+1)`.
Subtracting, we have `S - rS = r^m - r^(n+1)`.
Factoring out `1 - r` on the left and dividing by this quantity, we obtain `S = (r^m - r^(n+1))/(1-r)`.