6

您所在的位置:网站首页 c语言sort函数编写 6

6

#6| 来源: 网络整理| 查看: 265

有一组学生数据,每个数据中含有三门课成绩,请按成绩总和从高到低对这组数据进行排序。 编写函数calc求出每名学生的总分。 编写函数sort按每名学生的总分从高到低对这组数据进行排序

函数接口定义:

void calc(struct student *p,int n); void sort(struct student *p,int n);

其中 p 和 n 都是用户传入的参数。 函数calc求出p指针所指的结构体数组中 n 名学生各自的总分。 函数sort对p指针所指的结构体数组的学生数据按总分降序排序。

裁判测试程序样例:

#include struct student { int num; char name[15]; float score[3]; float sum; }; void calc(struct student *p,int n); void sort(struct student *p,int n); int main() { struct student stu[5]; int i,j; float f; for(i=0;i scanf("%f",&f); stu[i].score[j]=f; } } calc(stu,5); sort(stu,5); for(i=0;i for(int i=0; i struct student a; for(int i=0; i if(p[i].sum


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3