Go--求数组奇偶数之和
package main //申明main包 import "fmt" // 导入fmt标准库 func main() { arr := [...]int{01, 11, 22, 33, 44, 55, 66, 77, 88, 99, 98, 87, 76, 65, 54, 43, 32, 21, 10} evenList, oddList := []int{}, []int{} evenSum, oddSum := 0, 0 for _, value := range arr { if value%2 == 0 { evenList = append(evenList, value) evenSum += value } else { oddList = append(oddList, value) oddSum += value } } fmt.Println("偶数为:", evenList, "偶数之和为:", evenSum) fmt.Println("奇数为:", oddList, "奇数之和为:", oddSum) }