Created
April 23, 2019 20:47
-
-
Save lowewenzel/3663556e331be53d240e0f88d4e6157c to your computer and use it in GitHub Desktop.
Linear Sum Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func calcSum(numbers []int, left int, right int) int { | |
sum := 0 | |
for i := left; i < right; i++ { | |
sum += numbers[i] | |
} | |
return sum | |
} | |
func main() { | |
numbers := []int{1, 5, 2, 7, 1, 9} | |
fmt.Println(calcSum(numbers, 0, len(numbers))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment