int[] score = new int[]{90,65,88,70,46,81,100,68};
string[] name = new string[]{"景珍","林惠洋","成蓉","洪南昌","龙玉良","单江开","田武山","王三明"};
int sum=0,avg;
int m;
for(int i=0;i<score.Length;i++)
{
sum += score[i];
}
avg = sum / score.Length;
Console.WriteLine("平均分是" + avg + ",高于平均分的有:");
for(int i=0;i<score.Length;i++)
{
if(score[i] > avg)
{
m = i;
Console.Write(name[m] + " ");
}
}
以上是我的代码
输出中的逗号和冒号必须是中文符号
以下是我的代码,楼主连注释都没有,实在懒得看
static void Main(string[] args)
{
string []name = new string[]{"景珍","林惠洋","成蓉","洪南昌","龙玉民","单江开","田武山","王三明"};
double []score =new double[]{90,65,88,70,46,81,100,68};
double avg =0;
double sum = 0; // 声明各种变量;
for (int i =0;i<score.Length;i++)
{
sum+=score[i];
} // 总分;
avg = sum/score.Length;
Console.Write("平均分是"+avg+",高于平均分的有:");//平均分;
//接下来是求高于平均分
for(int j = 0; j<score.Length;j++)
{
if(score[j]>avg)
{
Console.Write( name[j]+" " );
}
}
在第二个for循环中间的if条件句后面加else
{
continue;
}
输出第一行的逗号用中文的逗号,下面输出名字可以直接用Console.Write(name[i]+" ");