trying_out_go/playground/averageVariadic.go

17 lines
288 B
Go

package main
import "fmt"
func average(numbers ...float64) float64 {
var sum float64 = 0
for _, number := range numbers {
sum += number
}
return sum / float64(len(numbers))
}
func averageVariadic() {
fmt.Println(average(100, 50))
fmt.Println(average(90.7, 89.7, 98.5, 92.3))
}