得出所输入分数的最大值最小值以及平均值

int[] chengji = new int[10];
int max = 0, min = 0, sum = 0;
for (int i = 0; i < 10; i++)
{
Console.Write("请输入第{0}个人的成绩:", i + 1);
chengji[i] = int.Parse(Console.ReadLine());
sum += chengji[i];

if (i == 0)
{
max = chengji[i];
min = chengji[i];
}
if (max < chengji[i])
{
max = chengji[i];
}
if (min > chengji[i])
{
min = chengji[i];
}

}
Console.WriteLine("最大的分数为:{0}", max);
Console.WriteLine("最小的分数为:{0}", min);
Console.WriteLine("平均分数为:{0}", sum / 10);

posted on 2015-09-22 10:25  路人甲zzz  阅读(213)  评论(0编辑  收藏  举报

导航