c编程:有一个一维数组,存放10个学生成绩,编写程序,求出平均分,最高分和最低分,并输出.

2024-11-20 22:34:07
推荐回答(1个)
回答1:

int main()
{
int score[10] = {32,56,67,78,43,22,23,89,91,9};
int i=0;
int sc_min, sc_max, sc_all=0;
float sc_aver =0;
sc_min = score[0];
sc_max = score[0];
sc_all = score[0];
for(i=1;i<10;i++)
{
sc_all += score[i];
if(sc_min > score[i])
sc_min = score[i];
if(sc_max < score[i])
sc_max = score[i];

}

sc_aver = sc_all / 10;
printf("max score: %d",sc_max);
printf("min score: %d",sc_max);
printf("average score: %d",sc_aver);
return 0;
}