Created
May 27, 2014 07:26
-
-
Save shockalotti/54b0c94e71df577104e7 to your computer and use it in GitHub Desktop.
Go Golang - average function
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
package main | |
import "fmt" | |
func average(xs[]float64)float64 { | |
total:=0.0 | |
for _,v:=range xs { | |
total +=v | |
} | |
return total/float64(len(xs)) | |
} | |
func main() { | |
xs:=[]float64{98,93,77,82,83} | |
fmt.Println(average(xs)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment