weibo_吉大熊先生_0
2017-01-03 17:54
for(int i=0;i<score.Length;i++){ sum+=score[i]; } avg=sum/score.Length; Console.Write("平均分是"+avg+",高于平均分的有:"); for(int j=0;j
avg){ Console.Write(name[j]+" "); } } 哪错了????;j++){>string[] name={"景珍","林惠洋","成蓉","洪南昌","龙玉民","单江开","田武山","王三明"};
int[] score={90,65,88,70,46,81,100,68};
int sum=0;
for(int i=0;i<8;i++)
{
sum+=score[i];
}
float avg=sum/score.Length;
Console.Write("平均分是{0},高于平均分的有:",avg);
for(int a=0;a<8;a++)
{
if(score[a]>avg)
Console.Write(name[a]+" ");
}
for (int i = 0; i < score.Length; i++)
{
sum += score[i];
}
ave = sum / score.Length;
Console.WriteLine("平均分是{0},高于平均分的有:", ave);
for (int j = 0; j < score.Length; j++)
{
if (score[j] > ave)
{
Console.Write(name[j] + " ");
}
}
打印高于平均分的人姓名那个for循环有问题。你可以改为
for (int j = 0; j < name.Length;j++ )
{
if(score[j] > avg)
Console.Write(name[j]+" ");
}
C#开发轻松入门
254118 学习 · 1459 问题
相似问题