using System;
namespace Test
{
class Program
{
static void Main(string[] args)
{
int[] score = { 90, 65, 88, 70, 46, 81, 100, 68 };
string[] name = { "景珍", "林慧洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" };
double sum = 0;
double avg;
for (int i = 0; i < score.Length; i++)
{
double avg2;
sum += score[i];
//Console.WriteLine(sum);//
avg2 = sum / 8;
if (score[i] > avg2)
{
Console.WriteLine("当前高于平均分的有" + name[i]);
}
}
avg = sum / 8;
Console.Write("平均分为" + avg);
Console.ReadKey();
}
}
}
// 创建姓名数组,存储8位同学的姓名
string[] names = new string[]{"景珍","林惠洋","成蓉","洪南昌","龙玉民","单江开","田武山","王三明"};
// 创建分数数组,存储9位同学的分数
int[] scores = new int[]{90,65,88,70,46,81,100,68};
// 循环数组,累加总分
int sum = 0; // 记录总分
for(int i = 0; i < scores.Length; i++){
sum += scores[i];
}
// 计算平均分
int avg = sum / scores.Length;
Console.WriteLine("平均分是{0},高于平均分的有:", avg);
// 循环每一位同学的分数,并在其内判断每一位同学的分数是否大于平均分,如果大于则打印出这位同学的姓名
for(int i = 0; i < scores.Length; i++){
if(scores[i] > avg){
Console.Write(names[i] + " ");
}
}
int[] score = new int[] { 90, 65, 88, 70, 46, 81, 100, 68 };
string[] name = new string[] { "景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" };
int sum = 0, ave;
for (int i = 0; i < score.Length; i++)
{
sum += score[i];
}
ave = sum / score.Length;
Console.WriteLine("平均分是{0},高于平均分的有:", ave);//特别注意这里的{0}后面的逗号是中文的逗
//号后面有空格, 冒号也是中文下的!!
for (int k = 0; k < score.Length; k++)
{
if (score[k] > ave)
{
Console.Write(name[k]+" ");
}
}