Last active
March 3, 2021 14:40
-
-
Save shockalotti/74cc6a0f0529917003c5 to your computer and use it in GitHub Desktop.
Go golang - average array of 5 numbers (more efficient)
This file contains 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 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))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is result correct if one of elements is 0?