栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【无标题】利用C语言结构体计算输入的每一位学生的平均分数,并存入结构体中。

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【无标题】利用C语言结构体计算输入的每一位学生的平均分数,并存入结构体中。

#include
#include
#include
#define AS 20
#define ZX 15
#define CSIZE 4
struct aa {
	char q[AS];
	char w[ZX];
};
struct student {
	struct aa name;
	float grade[AS];
	float e[AS];
};
void san(void);
void qq(struct student x[],int h);
void ww(struct student f[]);
struct student s[CSIZE];
int main(void)
{
	int c = 0;
	int p = 0;
	while (p < CSIZE)
	{
		printf("请输入学生姓:");
		gets_s(s[p].name.q, AS - 1);
		printf("请输入学生名:");
		gets_s(s[p].name.w, ZX - 1);
		printf("请输入学生分数:");
		while ((c = scanf_s("%f,%f,%f", &s[p].grade[0], &s[p].grade[1], &s[p].grade[2])) != 3)
		{
			printf("分数输入错误,请重新输入:");
		}
		san();
		qq(s,p);
		p++;
	}
	ww(s);
	return 0;
}
void san(void)
{
	while (getchar() != 'n')
		continue;
}
void qq(struct student x[],int h)
{
	float a = 0;
	a = x[h].grade[0] + x[h].grade[1] + x[h].grade[2];
	x[h].e[0] = a/3;
	printf("3门平均分数%.3fn", x[h].e[0]);
}
void ww(struct student f[])
{
	float s = 0;
	float j = 0;
	for (int y = 0; y < CSIZE; y++)
	{
		printf("姓名:%s%sn", f[y].name.q, f[y].name.w);
		printf("3门分数:%.2f %.2f %.2fn", f[y].grade[0], f[y].grade[1], f[y].grade[2]);
		printf("3门平均分数:%.2fn", f[y].e[0]);
		s = f[y].e[0] + s;
	}
	j = s / CSIZE;
	printf("班级平均分数:%f", j);
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/850318.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号