package main import "fmt" /* 二维数组 方式一:var arr [2][6]int{{},{}} 方式二:arr :=[...][6]int{{},{}} */ func main() { //定义二维数组 var arr [4][6]int arr[1][2]=1 arr[2][1]=2 arr[2][3]=3 for _,v:=range arr{ for _,j:=range v{ fmt.Print(j," ") } fmt.Println() } scores() } func scores(){ var scores [3][5]float64 for i,v:=range scores{ for ii,_:=range v{ fmt.Printf("请输入第%v班的第%v个学生的成绩:\n",i+1,ii+1) fmt.Scanln(&scores[i][ii]) } } var eachClassAvg float64 for i,v:=range scores{ var studentScores float64 for _,vv:=range v{ studentScores +=vv } eachClassAvg += studentScores fmt.Printf("班级%d平均分是:%.2f,班级%d的总分是:%v\n",i+1,studentScores/float64(len(v)),i+1,studentScores) } fmt.Printf("全部班级的:总分%.2f 平均分是%.2f",eachClassAvg,eachClassAvg/15.0) //fmt.Println(scores) }