string[] name = new string[] { "景珍", "林慧洋", "成蓉", "洪南昌", "龙玉民", "单开江", "田武山", "王三明" };
int[] score = new int[] { 90, 65, 88, 70, 46, 81, 100, 68 };
int sum = 0, avg;
for (int i= 0; i < score.Length; i++)
{
sum += score[i];
}
avg = sum / score.Length;
Console.Write("平均分是{0},高于平均分的有:", avg);
for (int i = 0; i < score.Length; i++)
{
if (score[i] > avg)
{
Console.Write(name[i]+" ");
}
}
string[] name = { "景珍", "林惠洋", "成蓉", "洪南昌", "龙玉民", "单江开", "田武山", "王三明" };
int[] score = { 90, 65, 88, 70, 46, 81, 100, 68 };
int avg=0;
int sum=0;
for(int i=0;i<score.Length;i++)
{
sum+=score[i];
}
avg=sum/score.Length;
Console.WriteLine("平均分数是{0},高于平均分的有",avg);
for(int i=0;i<score.Length;i++)
{
if(scroe[i]>avg)
{
Consile.Write("{0} ",name[i]);
}
}
你和慕课网设置的答案不一样,代码是正确的 可以没有换行或者那个汉子打错了。
不是i重定义,因为已经提示运行成功了,应该是输出的格式跟要求的不一样,在“高于平均分的有:”后面应该换一行,加一句Console.WriteLine();应该就好了
是不是i重复定义了