Last active
August 29, 2015 14:03
-
-
Save mcihad/7d1a8758c269a11a4b81 to your computer and use it in GitHub Desktop.
Go dili ilk deneme sum,avg, min,max
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 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