不断掉发线
2016-08-14 22:35
string[] name = new string[8];
int[] score = new int[8];
for (int i = 0; i < name.Length; i++)
{
Console.Write("输入姓名:");
name[i] = Console.ReadLine();
Console.Write("输入分数:");
score[i] = int.Parse(Console.ReadLine());
}
int sum = 0, avg;
for (int i = 0; i < score.Length; i++)
{
sum += score[i];
}
avg = sum / score.Length;
Console.WriteLine("平均分是"+avg+",高于平均分的有");
for (int i = 0; 0 < score.Length; i++)
if (score[i] > avg)
Console.Write(name[i]+" ");
for (int i = 0; 0 < score.Length; i++)
//这一行中,请把中间的循环条件改为i<score.Length,不然程序会一直在这里循环。
for (int i = 0; 0 < score.Length; i++)
同学你好好看看这句代码
你可以参考一下我的代码
string[] name = { "景珍", "林惠洋", "成蓉", "洪南昌","龙玉民","单江开","田武山","王三明" };
int[] score = { 90,65,88,70,46,81,100,68};
int sum = 0;
double avg;
//计算总分
for (int i = 0; i < score.Length; i++)
{
sum += score[i];
}
//计算平均分
avg = sum / score.Length;
Console.Write("平均分是"+avg+",");
//统计高于平均分的人数并逐一输出
Console.WriteLine("高于平均分的有:");
int j;
for ( j= 0; j< name.Length; j++)
{
if (score[j] > avg)
{
Console.Write(name[j]+" ");
}
}
C#开发轻松入门
254118 学习 · 1459 问题
相似问题