|
@@ -1,39 +1,39 @@
|
|
|
#include <stdio.h>
|
|
|
-#define N 3 // 学生数为3
|
|
|
-struct student // 建立结构体类型struct student
|
|
|
- {int num; // 学号
|
|
|
- char name[20]; // 姓名
|
|
|
- float score[3]; // 3门课成绩
|
|
|
- float aver; // 平均成绩
|
|
|
+#define N 3 // 瀛︾敓鏁颁负3
|
|
|
+struct student // 寤虹珛缁撴瀯浣撶被鍨媠truct student
|
|
|
+ {int num; // 瀛﹀彿
|
|
|
+ char name[20]; // 濮撳悕
|
|
|
+ float score[3]; // 3闂ㄨ�鎴愮哗
|
|
|
+ float aver; // 骞冲潎鎴愮哗
|
|
|
};
|
|
|
|
|
|
int main()
|
|
|
- {void input(struct student stu[]); // 函数声明
|
|
|
- struct student max(struct student stu[]); // 函数声明
|
|
|
- void print(struct student stu); // 函数声明
|
|
|
- struct student stu[N],*p=stu; // 定义结构体数组和指针
|
|
|
- input(p); // 调用input函数
|
|
|
- print(max(p)); // 调用print函数,以max函数的返回值作为实参
|
|
|
+ {void input(struct student stu[]); // 鍑芥暟澹版槑
|
|
|
+ struct student max(struct student stu[]); // 鍑芥暟澹版槑
|
|
|
+ void print(struct student stu); // 鍑芥暟澹版槑
|
|
|
+ struct student stu[N],*p=stu; // 瀹氫箟缁撴瀯浣撴暟缁勫拰鎸囬拡
|
|
|
+ input(p); // 璋冪敤input鍑芥暟
|
|
|
+ print(max(p)); // 璋冪敤print鍑芥暟,浠�ax鍑芥暟鐨勮繑鍥炲€间綔涓哄疄鍙�
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-void input(struct student stu[]) // 定义input 函数
|
|
|
+void input(struct student stu[]) // 瀹氫箟input 鍑芥暟
|
|
|
{int i;
|
|
|
- printf("请输入各学生的信息:学号、姓名、三门课成绩:\n");
|
|
|
+ printf("璇疯緭鍏ュ悇瀛︾敓鐨勪俊鎭�細瀛﹀彿銆佸�鍚嶃€佷笁闂ㄨ�鎴愮哗:\n");
|
|
|
for(i=0;i<N;i++)
|
|
|
- {scanf("%d %s %f %f %f",&stu[i].num,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.0; // 求各人平均成绩
|
|
|
+ {scanf("%d %s %f %f %f",&stu[i].num,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.0; // 姹傚悇浜哄钩鍧囨垚缁�
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-struct student max(struct student stu[]) // 定义max 函数
|
|
|
-{int i,m=0; // 用m存放成绩最高的学生在数组中的序号
|
|
|
+struct student max(struct student stu[]) // 瀹氫箟max 鍑芥暟
|
|
|
+{int i,m=0; // 鐢╩瀛樻斁鎴愮哗鏈€楂樼殑瀛︾敓鍦ㄦ暟缁勪腑鐨勫簭鍙�
|
|
|
for(i=0;i<N;i++)
|
|
|
- if (stu[i].aver>stu[m].aver) m=i; // 找出平均成绩最高的学生在数组中的序号
|
|
|
- return stu[m]; // 返回包含该生信息的结构体元素
|
|
|
+ if (stu[i].aver>stu[m].aver) m=i; // 鎵惧嚭骞冲潎鎴愮哗鏈€楂樼殑瀛︾敓鍦ㄦ暟缁勪腑鐨勫簭鍙�
|
|
|
+ return stu[m]; // 杩斿洖鍖呭惈璇ョ敓淇℃伅鐨勭粨鏋勪綋鍏冪礌
|
|
|
}
|
|
|
|
|
|
-void print(struct student stud) // 定义print函数
|
|
|
- { printf("\n成绩最高的学生是:\n");
|
|
|
- printf("学号:%d\n姓名:%s\n三门课成绩:%5.1f,%5.1f,%5.1f\n平均成绩:%6.2f\n",stud.num,stud.name,stud.score[0],stud.score[1],stud.score[2],stud.aver);
|
|
|
+void print(struct student stud) // 瀹氫箟print鍑芥暟
|
|
|
+ { printf("\n鎴愮哗鏈€楂樼殑瀛︾敓鏄�:\n");
|
|
|
+ printf("瀛﹀彿:%d\n濮撳悕:%s\n涓夐棬璇炬垚缁�:%5.1f,%5.1f,%5.1f\n骞冲潎鎴愮哗:%6.2f\n",stud.num,stud.name,stud.score[0],stud.score[1],stud.score[2],stud.aver);
|
|
|
}
|