Created
February 22, 2022 05:48
-
-
Save nidhi-canopas/a2346e86a8d77dcb70aefa8134128014 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import "fmt" | |
func main() { | |
s := []int{10, 20, 30} | |
sum := sumSlice(s) | |
fmt.Println("Sum of slice elements : ", sum) | |
} | |
func sumSlice(array []int) int { | |
sum := 0 | |
for _, item := range array { | |
sum += item | |
} | |
return sum | |
} | |
output: | |
Sum of slice elements : 60 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment