9学生中三门课平均分最高的那个学生信息

问题描述

输入3个学生包含学号,姓名和三门课的成绩,中间以空格分开,然后输出最大平均分的那个学生的信息

代码

#include<stdio.h>
#include<string.h>
# define N 3
typedef struct Student{
	long id;
	char name[20];
	float score[3];
	float aver;
}Student;
//Student stu_1={10101,"张三",67,93,87.5};
//Student stu_2={10102,"李四",86,82,71};
//Student stu_3={10103,"王五",79,62,97};
void input(Student stu[]);//函数的声明 
Student max(Student stu[]);
void print(Student stu);

int main()
{
	int i,j;
	Student stu[N],*p;
	p=stu;//把首地址给p指针 
	input(p); //对input 
	print(max(p));//把p指针指向的传过去,其实stu[N]也可以 
	return 0;
}
void input(Student stu[])//先传入main里面创建的空的 
{
	int i;
	for(i=0;i<N;i++){
		printf("请输入学生的信息:学号、姓名、三门课的信息:");
		scanf("%d %s %f %f %f",&stu[i].id,&stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
		stu[i].aver= (stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;
	}
} 

Student max(Student stu[]){//不是任何类型,返回的是一个Student类 
	int i,m=0;
	int max=0;
	for(i=1;i<N;i++){
		if(stu[i].aver>max){
			max=stu[i].aver;
			m=i;
		}
	}
	return stu[m]; //返回对象 
}

void print(Student stu){//此时的p指针只是指向那一个对象了 
	printf("学生学号:%d姓名:%s三门课成绩:%f %f %f\n",stu.id,stu.name,stu.score[0],stu.score[1],stu.score[2]);
	printf("他最高的平均成绩是:%f\n",stu.aver);
}

结果

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lanmy_dl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值