Skip to content

Instantly share code, notes, and snippets.

@mcihad
Last active August 29, 2015 14:03
Show Gist options
  • Save mcihad/7d1a8758c269a11a4b81 to your computer and use it in GitHub Desktop.
Save mcihad/7d1a8758c269a11a4b81 to your computer and use it in GitHub Desktop.
Go dili ilk deneme sum,avg, min,max
package main
import "fmt"
func sum(vals []int) (r int) {
for _, val := range vals {
r += val
}
return
}
func avg(vals []int) (r float64) {
for _, val := range vals {
r += float64(val)
}
r = r / float64(len(vals))
return
}
func max(vals []int) (r int) {
r = vals[0]
for _, val := range vals {
if val > r {
r = val
}
}
return
}
func min(vals []int) (r int) {
r = vals[0]
for _, val := range vals {
if val < r {
r = val
}
}
return
}
func main() {
fmt.Println(sum([]int{12, 22, 65, 45}))
fmt.Println(avg([]int{12, 33, 65, 45}))
fmt.Println(max([]int{12, 33, 65, 45}))
fmt.Println(min([]int{12, 33, 65, 45, 1}))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment