-->
当前位置:首页 > 题库 > 正文内容

函数题:结构体-成绩单排序

Luz3年前 (2022-04-13)题库891

定义函数处理结构体数组,按成绩从高到低降序排列。
### 函数接口定义:
c++

struct stu {
int num;
char name[20];
int score; };

void fun ( struct stu *p, int n );

p是结构体数组的起始地址,n是结构体单元个数。
结构体成员:num是学号,name是姓名,score是成绩。
### 裁判测试程序样例:
c++
在这里给出函数被调用进行测试的例子。例如:
#include <stdio.h>
struct stu{
int num;
char name[20];
int score;
};
void fun( struct stu *p, int n );
int main()
{ struct stu a[20];
int n, i;
scanf("%d", &n);
for(i = 0; i < n; i++){
scanf("%d%s%d", &a[i].num, a[i].name, &a[i].score);
}
fun(a,n);
for(i = 0; i < n; i++)
printf("%d %s %d\n", a[i].num, a[i].name, a[i].score);
return 0;
}
/* 请在这里填写答案 */


### 输入样例:

在这里给出一组输入。例如:

in
6
1001 anny 85
1002 boy 75
1003 car 65
1004 dan 55
1005 emm 95
1006 pa 35


### 输出样例:

在这里给出相应的输出。例如:

out
1005 emm 95
1001 anny 85
1002 boy 75
1003 car 65
1004 dan 55
1006 pa 35







答案:若无答案欢迎评论

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。