未分类题
以下程序的功能是:处理由学号和成绩组成的学生记录,N名学生的数据已在主函数中放入结构体数组s中,它的功能是:把分数最高的学生数据放在h所指的数组中,注意:分数高的学生可能不只一个,函数返回分数最高学生的人数。请填空。
#include
#define N 16
typedef struct
{char num[10];
int s ;
} STREC;
int fun (STREC *a, STREC *b)
{int i,j=0,max=a[0].s;
for(i=0;i
if(max
for(i=0;i
if(【20】)b[j++]=a[i];
return j;
}
main ()
{STREC s[N]={{ 'GA005',85},{'GA003',76},{'GA002',69},{'GA004',85},
{'GA001',91},{'GA007',72},{'GA008',64},{'GA006',87},
{ 'GA015',85},{'GA013',91},{'GA012',64},{'GA014',91},
{'GA011',66},{'GA017',64},{'GA018',64},{'GA016',72}
};
STREC h[N];
int i, n;FILE *out;
n=fun(s,h);
printf('The %d highest score :\n',n);
for (i=0; i
printf('%s M\n ',h[i].num,h[i].s);
printf('\n');
out=fopen('out15.dat', 'w');
fprintf(out, '%d\n',n);
for(i=0; i
fprintf(out, 'M\n ',h[i].s);
fclose(out);
}
A.s;
B.num,h[i].s);
C.dat',
D.s);
【参考答案】
max==a[i].s