【C语言】有n个结构体变量,内含学生号, 姓名和三门课成绩。要求输出平均成绩最高学生的信息。

12 篇文章 7 订阅
9 篇文章 0 订阅
//有n个结构体变量,内含学生号, 姓名和三门课成绩。要求输出平均成绩最高学生的信息。
#include <stdio.h>
#define N 3
struct Student
{
	int num;
	char name[20];
	float socre[3];
	float aver;
};
void input(struct Student stu[])
{
	int i;
	printf("Çë·Ö±ðÊäÈë¸÷ѧÉúµÄÐÅÏ¢£ºÑ§ºÅ£¬ÐÕÃû£¬ÈýÃſγɼ¨\n");
	for(i=0;i<N;i++)
	{
		scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i].socre[0],&stu[i].socre[1],&stu[i].socre[2]);
		stu[i].aver=(stu[i].socre[0]+stu[i].socre[1]+stu[i].socre[2])/3;
	}
}
struct Student max(struct Student stu[])
{
	int i,m=0;
	for(i=0;i<N;i++)
		if(stu[i].aver>stu[m].aver)
			m=i;
	return stu[m];
}
void print(struct Student stud)
{
	printf("\n³É¼¨×î¸ßµÄѧÉúÊÇ£º\n");
	printf("ѧºÅ£º%d\nÐÕÃû£º%s\nÈýÃſγɼ¨£º%5.1f,%5.1f,%5.1f\nƽ¾ù³É¼¨£º%6.2f\n",stud.num,stud.name,stud.socre[0],stud.socre[1],stud.socre[2],stud.aver);
}
int main()
{
	struct Student stu[N],*p=stu;
	input(p);
	print(max(p));
	return 0;
}

  • 7
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值