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