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-01-09 16:16:31 -07: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++ {
|
|
|
|
s += a[i]
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
2009-04-15 21:27:45 -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
|
|
|
}
|