finite geometric series sum formula code example Example: formula for finite geometric series a(1-rⁿ)/(1-r).