#include <stdio.h>
int main ()
{
float score[5][3] = {{80, 75, 56}, {59, 65, 71}, {59, 63, 70},
{85, 45, 90}, {76, 77, 45}};
//求每一科的平均分
float avg[3] = {0};
//每科不及格统计
int statistic[3] = {0};
float sum = 0;
for (int i = 0; i < 3; i ++)
{
for (int j = 0; j < 5; j ++)
{
sum += score[j][i];
if (score[j][i] < 60)
{
statistic[i] ++;
}
}
avg[i] = sum / 5;
sum = 0;
}
for (int i = 0; i < 3; i ++)
{
printf("%f ", avg[i]);
}
printf("\n");
for (int i = 0; i < 3; i ++)
{
printf("%d ", statistic[i]);
}
printf("\n");
}
每个人三科成绩组成二维数组,求每一科的平均分,以及每科不及格统计代码实现
最新推荐文章于 2024-11-07 12:47:29 发布