Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shockalotti/74cc6a0f0529917003c5 to your computer and use it in GitHub Desktop.
Save shockalotti/74cc6a0f0529917003c5 to your computer and use it in GitHub Desktop.
Go golang - average array of 5 numbers (more efficient)
package main
import "fmt"
func main() {
x:= [5]float64{
98,
93,
77,
82,
83,
}
var total float64 = 0
for _, value:= range x {
total += value
}
fmt.Println(total/float64(len(x)))
}
@antidepresiv
Copy link

Is result correct if one of elements is 0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment