1! + 2! + 3! + 4!的和->Swift

func getSum(number: Int) -> Int {
//求某个数阶乘的结果
func getFactorIal(num: Int) -> Int {
var sum = 1
for _ in 1...num {
sum += 1
}
return sum
}
var total = 0
for item in 1...number {
total += getFactorIal(num: item)
}
return total
}

print(getSum(number: 3))

你可能感兴趣的:(1! + 2! + 3! + 4!的和->Swift)