输入五个学生的成绩,得到成绩表

int[,] a = new int[5, 6];

for (int i = 0; i < 5;i++ )
{
a[i, 0] = i + 1;
Console.Write("请输入{0}号学生的语文成绩",i+1);
int yw = Convert.ToInt32(Console.ReadLine());
a[i, 1] = yw;
Console.Write("请输入{0}号学生的数学成绩",i+1);
int sx = Convert.ToInt32(Console.ReadLine());
a[i, 2] = sx;
Console.Write("请输入{0}号学生的英语成绩",i+1);
int yy = Convert.ToInt32(Console.ReadLine());
a[i, 3] = yy;
a[i, 4] = (yw + sx + yy) / 3;

Console.Clear();
int sum = yw + sx +yy;
a[i, 5] = sum;

}


for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 5 - i; j++)
{
if (a[j, 5] > a[j - 1, 5])
{
int txh = a[j - 1, 0];
a[j - 1, 0] = a[j, 0];
a[j, 0] = txh;

int tyw = a[j - 1, 1];
a[j - 1, 1] = a[j, 1];
a[j, 1] = tyw;

int tsx = a[j - 1, 2];
a[j - 1, 2] = a[j, 2];
a[j, 2] = tsx;

int tzf = a[j - 1, 3];
a[j - 1, 3] = a[j, 3];
a[j, 3] = tzf;

int tdd = a[j - 1, 4];
a[j - 1, 4] = a[j, 4];
a[j, 4] = tdd;

int tee = a[j - 1, 5];
a[j - 1, 5] = a[j, 5];
a[j, 5] = tee;
}
}
}

Console.WriteLine("学号 语文 数学 英语 总分");

for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 6; j++)
{

if (a[i, j] < 60)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(a[i, j] + " ");

}

else
{

Console.ForegroundColor = ConsoleColor.White;
Console.Write(a[i, j] + " ");
}



}
Console.Write(" ");


}

原文地址:https://www.cnblogs.com/zzc134680/p/5424164.html