题目:一个班6个人,从键盘输入每个学号语文,数学,外语成绩(不需输入学号)。输出:学生成绩表(包括每个人的总分),每科的平均分。
1 static void Main(string[] args) 2 { 3 int [,] a=new int [6,5]; 4 5 for(int i=0;i <6;i ++) 6 { 7 Console .WriteLine ("请输入第{0}个学生的语文成绩",i+1);// i+1 序列号第一个学生 8 int yuwen=Convert .ToInt32 (Console .ReadLine ()); 9 Console .WriteLine ("请输入第{0}个学生的数学成绩",i+1); 10 int shuxue=Convert .ToInt32 (Console .ReadLine ()); 11 Console .WriteLine ("请输入第{0}个学生的英语成绩",i+1); 12 int yingyu=Convert .ToInt32 (Console .ReadLine ()); 13 14 a[i, 0] = i + 1; //学号 15 a[i, 1] = yuwen; 16 a[i, 2] = shuxue; 17 a[i, 3] = yingyu ; 18 a[i, 4] = yuwen +shuxue +yingyu ; 19 20 21 } 22 for (int i = 1; i <=6; i++) 23 { 24 25 for (int j = 1; j <= 6-i; j++) 26 { 27 if (a [j,4]>a[j-1,4]) 28 { 29 int xh = a[j - 1, 0]; 30 a[j - 1, 0] = a[j, 0]; 31 a[j, 0] = xh; 32 33 int yuwen = a[j - 1, 1]; 34 a[j - 1,1] = a[j, 1]; 35 a[j, 1] = yuwen ; 36 37 int shuxue= a[j - 1, 2]; 38 a[j - 1, 2] = a[j, 2]; 39 a[j, 2] = shuxue; 40 41 42 int yingyu = a[j - 1, 3]; 43 a[j - 1,3] = a[j,3]; 44 a[j, 3] = yingyu ; 45 46 47 int zhongfen = a[j - 1, 4]; 48 a[j - 1, 4] = a[j, 4]; 49 a[j, 4] = zhongfen ; 50 51 52 } 53 54 } 55 } 56 Console .WriteLine ("学号 语文 数学 英语 总分 名次"); 57 for (int i =0; i<6;i++) 58 { 59 Console .WriteLine ("{0} {1} {2} {3} {4} {5}",a[i,0],a[i,1],a[i,2],a[i,3],a[i,4],i+1); 60 61 } 62 63 64 65 }
显示的结果: