package main
import "fmt"
func main() {
scores := [6]int{95, 91, 39, 60, 21, 100} // 使用数组存储多个学生的成绩
sum := 0
fmt.Printf("数组长度是%v\n", len(scores))
fmt.Printf("数组指针内存地址是%p\n", &scores)
fmt.Printf("第一个值内存地址是%p\n", &scores[0])
fmt.Printf("第二个值内存地址是%p\n", &scores[1])
fmt.Printf("第三个值内存地址是%p\n", &scores[2])
fmt.Printf("第三个值内存地址是%p\n", &scores[3])
fmt.Printf("第三个值内存地址是%p\n", &scores[4])
fmt.Printf("第三个值内存地址是%p\n", &scores[5])
// 计算总成绩
for _, score := range scores {
sum += score
}
// 计算平均成绩
avg := float64(sum) / float64(len(scores)) // 使用 len(scores) 获取学生人数
fmt.Printf("总成绩是%v\n平均成绩是%.2f\n", sum, avg)
} |