static void Main(string[] args) { int [,] a = new int [6,5]; for (int i = 0; i < 6; i ++ ) { Console.WriteLine("请输入第{0}个同学的数学成绩",i +1); int sx = Convert .ToInt32( Console.ReadLine()); Console.WriteLine("请输入第{0}个同学的语文成绩", i + 1); int yw = Convert .ToInt32 ( Console.ReadLine()); Console.WriteLine("请输入第{0}个同学的英语成绩",i +1); int yy = Convert .ToInt32 ( Console.ReadLine()); a[i, 0]=i +1; a[i, 1]=sx ; a[i, 2]=yw ; a[i, 3]=yy ; a[i, 4] = sx + yw + yy; } for (int i = 1; i <= 5; i ++ ) { for (int j = 1; j <= 6 - i; j ++ ) { if (a[j ,4]>a [j -1 ,4]) { int xyw = a[j, 1]; a[j, 1] = a[j - 1, 1]; xyw=a [j-1, 1] ; int xsx = a[j, 2]; a[j, 2] = a[j - 1, 2]; xsx=a [j-1 ,2] ; int xyy = a[j, 3]; a[j, 3] = a[j - 1, 3]; a [j-1, 3]=xyy ; int xzf = a[j, 4]; a[j, 4] = a[j - 1, 4]; a[j - 1, 4] = xzf; } } } Console.WriteLine("学号\t语文\t数学\t英语\t总分\t名次"); for (int i = 0; i < 6; i ++ ) { Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}",a [i ,0],a [i ,1],a [i ,2],a [i ,3],a [i ,4],i +1); } } } }
时间: 2024-12-15 20:31:57