求助一道C语言编程题,题目如下

2024-11-08 11:22:18
推荐回答(1个)
回答1:


#include

int main(void)

{

int scores[5][3] = { { 60, 50, 30 },

{ 90, 50, 80 },

{ 100, 50, 60 },

{ 80, 90, 80 },

{ 90, 80, 60 }};

float average[5] = { 0.0 };//保存各个学生的平均分

int sum[5] = { 0 };//保存各个学生的总分

float average_scores[3] = { 0.0 };//保存各科的平均分

int sum_scores[3] = { 0 };//保存各科的总计分

int i, j;

int n;

float m;

for (i = 0; i < 5; i++)

{

sum[i] = scores[i][0] + scores[i][1] + scores[i][2];

average[i] = sum[i] / 3.0;

if (i <= 2)

{

sum_scores[i] = 0;

}

for (j = 0; j < 5; j++)

{

if (i >= 3)

{

break;

}

sum_scores[i] += scores[j][i];

}

if (i <= 2)

{

average_scores[i] = sum_scores[i] / 5.0;

}

}

printf("\t--------------------------------------------\n");

printf("\t编号\t语文\t数学\t英语\t平均分\t总分\n");

for (i = 0; i < 5; i++)

{

printf("\t%3d  ", i + 1);

for (j = 0; j < 3; j++)

{

printf("\t%d  ", scores[i][j]);

}

printf("\t%.2f  ", average[i]);

printf("\t%d  \n", sum[i]);

}

printf("\t平均分");

for (i = 0; i < 3; i++)

{

printf("\t%.2f  ", average_scores[i]);

}

m = (average_scores[0] + average_scores[1] + average_scores[2]) / 3.0;

printf("\t%.2f\t%.0f\n", m, m*3);

printf("\t总计分");

for (i = 0; i < 3; i++)

{

printf("\t%d  ", sum_scores[i]);

}

n = sum_scores[0] + sum_scores[1] + sum_scores[2];

printf("\t%.2f\t%d\n", n/3.0, n);

return 0;

}