5名学生,算数学总成绩和平均值,语文总成绩和平均值,英语总成绩和平均值

方法一

#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);
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值