#region ======一个班六个人,学号语文、数学、英语,接收成绩(不接受学号),输出学号成绩,总分、平均分======
//定义一个二维数组接收六个人的成绩
double[,] stu = new double[7, 6];
//接收成绩
Console.WriteLine("请输入每个人的语文、数学、英语成绩");
for (int i = 0; i < 6;i++ )
{
Console.WriteLine("请输入学生{0}的语文的成绩",i+1);
stu[i ,1] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入学生{0}的数学的成绩", i + 1);
stu[i , 2] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("请输入学生{0}的英语的成绩", i + 1);
stu[i,3] = Convert.ToInt32(Console.ReadLine());
stu[i, 0] = i + 1;
//总分
stu[i, 4] = stu[i, 1] + stu[i, 2] + stu[i, 3];
}
总分
//double[] sum = new double[6]; ;
//for (int i = 0; i < 6; i++)
//{
// for (int j = 0; j < 3; j++)
// {
// sum[i] = sum[i] + stu[i, j+1];
// }
// for (int t = 1; t < 7; t++)
// {
// stu[i, 4] = sum[i];
// }
//}
// 个人平均分
for (int i = 0; i < 6; i++)
{
stu[i, 5] = Convert.ToDouble((1.0 * stu[i,4] / 3).ToString("#.0"));
}
//学科平均分
double avg = 0;
double h =0;
for (int j = 1; j < 4; j++)
{
h = 0;
for (int i = 0; i < 5; i++)
{
h = h + stu[i+1, j];
stu[6, j] = Convert.ToDouble((h / 6).ToString("#.0")) ;
}
}
//打印输出
Console.WriteLine("学号\t语文\t数学\t英语\t总分\t平均分");
for (int i = 0; i < 7; i++)
{
Console.Write(stu[i, 0] + "\t");
for (int j = 1; j < 4; j++)
{
//======把不及格的用红字显示======
if (stu[i, j] < 60 && i<6)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(stu[i, j] + "\t");
Console.ForegroundColor = ConsoleColor.Gray;
}
else
{
Console.Write(stu[i, j] + "\t");
}
}
for (int j = 4; j < 6; j++)
{
Console.Write(stu[i, j] + "\t");
}
Console.WriteLine();
}
#endregion
Console.WriteLine();
Console.WriteLine("按照总分排序");
#region ====== 附加2:试着按照总分排序,显示名次出来。 ======
//打印输出
double[] zhong = new double[6];
for (int i = 1; i <= 6; i++)
{
for (int j = 1; j <= 7 - i; j++)
{
if (stu[j, 4] > stu[j - 1, 4])
{
double xh = stu[j-1, 0];
stu[j - 1, 0] = stu[j, 0];
stu[j,0] = xh;
double yw = stu[j - 1, 1];
stu[j - 1,1] = stu[j, 1];
stu[j,1] = yw;
double sx = stu[j - 1, 2];
stu[j - 1, 2] = stu[j, 2];
stu[j, 2] = sx;
double yy = stu[j - 1,3];
stu[j - 1,3] = stu[j, 3];
stu[j, 3] = yy;
double zf = stu[j - 1,4];
stu[j - 1,4] = stu[j, 4];
stu[j, 4] = zf;
double pjf = stu[j - 1,5];
stu[j - 1,5] = stu[j, 5];
stu[j,5] = pjf;
}
}
}
//打印输出
Console.WriteLine("学号\t语文\t数学\t英语\t总分\t平均分");
for (int i = 0; i < 7; i++)
{
Console.Write(stu[i, 0] + "\t");
for (int j = 1; j < 4; j++)
{
//======把不及格的用红字显示======
if (stu[i, j] < 60 && i<6)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(stu[i, j] + "\t");
Console.ForegroundColor = ConsoleColor.Gray;
}
else
{
Console.Write(stu[i, j] + "\t");
}
}
for (int j = 4; j < 6; j++)
{
Console.Write(stu[i, j] + "\t");
}
Console.WriteLine();
}
#endregion