计算学员的考试总成绩以及平均成绩
func main (){
sum,avg,count := GetScore(90,82.5,73,64.8)
fmt.Printf("学员共有 %d 门成绩,总成绩是 %0.2f ,平均成绩为 :%0.2f",count,sum,avg)
fmt.Println()
scores := []float64{92,72.5,74.5,89,87,74}
sum, avg, count = GetScore(scores...)
fmt.Printf("学员共有 %d 门成绩,总成绩是 %0.2f ,平均成绩为 :%0.2f",count,sum,avg)
}
func GetScore(scores ...float64) (sum,avg float64,count int) {
for _,values := range scores{
sum += values
count++
}
avg = sum/ float64((count))
return
}
本文来自博客园,作者:Chuan_Chen,转载请注明原文链接:https://www.cnblogs.com/wangcc7/p/12892087.html