计算学员的考试总成绩以及平均成绩

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
}

猜你喜欢

转载自www.cnblogs.com/wangcc7/p/12892087.html