Generation

generate functionSat, 12 Nov 2022

get the sum of odd numbers in a list

func sumOdd(numbers []int) int { sum := 0 for _, number := range numbers { if number % 2 != 0 { sum += number } } return sum } sumOdd([]int{1, 2, 3, 4, 5})

Questions about programming?Chat with your personal AI assistant