2008-09-11 11:21:02 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2009-03-18 15:09:16 -06:00
|
|
|
import "fmt"
|
|
|
|
|
2009-10-06 12:42:55 -06:00
|
|
|
func sum(a []int) int { // returns an int
|
2008-09-11 11:21:02 -06:00
|
|
|
s := 0;
|
|
|
|
for i := 0; i < len(a); i++ {
|
2009-10-06 12:42:55 -06:00
|
|
|
s += a[i];
|
2008-09-11 11:21:02 -06:00
|
|
|
}
|
2009-10-06 12:42:55 -06:00
|
|
|
return s;
|
2008-09-11 11:21:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
2009-10-06 12:42:55 -06:00
|
|
|
s := sum(&[3]int{1, 2, 3}); // a slice of the array is passed to sum
|
2009-03-18 15:09:16 -06:00
|
|
|
fmt.Print(s, "\n");
|
2008-09-11 11:21:02 -06:00
|
|
|
}
|