var names = new string[] { "景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" }; var score = new int[] { 90, 65, 88, 70, 46, 81, 100, 68 }; int sum = 0; int avg = 0; int index = 0; for (int x = 0; x < score.Length; x++) { sum += score[x]; } avg = sum / score.Length; Console.WriteLine("平均分是" + avg + ",高于平均分的有:"); for (int e = 0; e < score.Length; e++) { if (avg < score[e]) { index = e; } else { continue; } Console.Write(names[index] + " "); }
//学生姓名
string[] Name = new string[] { "景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" };
int[] Score = new int[] { 90, 65, 88, 70, 46, 81, 100, 68 };
int Sum = 0;
foreach(int x in Score)
{
Sum += x;
}
Sum /= Name.Length;
Console.WriteLine("平均分是{0},高于平均分的有:",Sum);
for (int i = 0;i<Name.Length;i++)
{
if (Score[i]>Sum)
{
Console.Write(Name[i]+' ');
}
}
Console.ReadKey();