方法一
#include <stdio.h>
int main()
{
int StuScore[5][3] = {
//张同学
{ 88, 70, 90 },
//王同学
{ 80, 80, 60 },
//李同学
{ 89, 60, 85 },
//赵同学
{ 80, 75, 78 },
//周同学
{ 70, 80, 80 }
};
int m = 0, n = 0;
int nStuTotalScore;
int nMathTotalScore = 0;
int nChineseTotalScore = 0;
int nEnglishTotalScore = 0;
printf("个人总成绩:\n");
for (m = 0; m < 5; m++)
{
nStuTotalScore = 0;
for (n = 0; n < 3; n++)
{
nStuTotalScore += StuScore[m][n];
switch (n)
{
case 0:
nMathTotalScore += StuScore[m][0];break;
case 1:
nChineseTotalScore += StuScore[m][1];break;
case 2:
nEnglishTotalScore += StuScore[m][2];break;
}
}
switch (m)
{
case 0:
printf("张同学:%d\n", nStuTotalScore);break;
case 1:
printf("王同学:%d\n", nStuTotalScore);break;
case 2:
printf("李同学:%d\n", nStuTotalScore);break;
case 3:
printf("赵同学:%d\n", nStuTotalScore);break;
case 4:
printf("周同学:%d\n", nStuTotalScore);break;
}
}
printf("小组数学总分:%d 小组数学平均分:%.2f\n",
nMathTotalScore, (double)nMathTotalScore / 5);
printf("小组语文总分:%d 小组语文平均分:%.2f\n",
nChineseTotalScore, (double)nChineseTotalScore / 5);
printf("小组英语总分:%d 小组英语平均分:%.2f\n",
nEnglishTotalScore, (double)nEnglishTotalScore / 5);
return 0;
}
方法二:
#include <stdio.h>
int z[] = {88,77,90};
int w[] = {80,80,60};
int l[] = {89,60,80};
int zh[] = {80,75,78};
int zhou[] = {70,80,80};
int main()
{
int sz = z[0] + w[0] + l[0] + zh[0] + zhou[0];
int sp = sz / 5;
printf("数学总:%d\n",sz);
printf("数学平均:%d\n",sp);
int ywz = z[1] + w[1] + l[1] + zh[1] + zhou[1];
int ywp = ywz / 5;
printf("语文总:%d\n",ywz);
printf("语文平均:%d\n",ywp);
int yyz = z[2] + w[2] + l[2] + zh[2] + zhou[2];
int yyp = yyz / 5;
printf("英语总:%d\n",yyz);
printf("英语平均:%d\n",yyp);
}