You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
package arrays
|
|
|
|
func Sum(a []int) int {
|
|
sum := 0
|
|
|
|
//aternatively
|
|
// for i := 0; i < 5; i++ {
|
|
// sum += a[i]
|
|
// }
|
|
|
|
// OR
|
|
|
|
// for i := range a {
|
|
// sum += a[i]
|
|
// }
|
|
|
|
// OR
|
|
|
|
for _, v := range a {
|
|
sum += v
|
|
}
|
|
return sum
|
|
}
|