/** * Beispiele aus * * - Algorithmen und Datenstrukturen für Dummies * - von Andreas Gogol-Döring und Thomas Letschert * - Verlag Wiley-VCH; Oktober 2019 * - Kapitel 1, Das sind Algorithmen * * @author A. Gogol-Döring, Th. Letschert */ import Foundation struct AuD_01_01_Summation { static func Summation1(n: Int) -> Int { var s: Int = 0 for i in 1...n { s = s + i } return s } static func Summation2(n: Int) -> Int { return n * ((n + 1) / 2) } static func run() { print(Summation1(n: 5)) print(Summation2(n: 5)) } }