C语言,求高手 学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请

编写函数fun,它的功能是:把分数最低的学生数据放在h所指的数组中,注意:分数最低的学生可能不止一个,函数返回分数最低的学生的人数:
#include<stdio.h>
#include<string.h>
#define N 10
typedef struct
{
char num[10];
int s;
}STREC;
int fun(STREC *a,STREC *b)
{
????
}
int main()
{
STREC s[N]={{"GA05",85},{"GA03",76},{"GA02",69},{"GA04",85},{"GA01",91},{"GA07",72},{"GA08",64},{"GA09",64},{"GA10",85},{"GA06",64}};
STREC h[N];
int i,n;
n=fun(s,h);
printf("The %d lowest score:\n",n);
for(i=0;i<n;i++)
printf("%d %4d\n",h[i].num,h[i].s);
printf("\n");
}

发现你主程序有个小错误,已经改正,下列程序,望采纳

#include<stdio.h>
#include<string.h>
#define N 10
typedef struct
{
char num[10];
int s;
}STREC;
int fun(STREC *a,STREC *b)
{
int i,j=0;
int min;
for(min = a->s;a->s > 0 && a->s <= 100 ;a++,j++)
{
if(a->s <min)min = a->s;
}
for(a-=j,i=0;j>0;a++,j--)
{
if(a->s==min)
{
//printf("\n%s ",a->num,a->s);
strcpy(b->num,a->num);
b++->s = a->s;i++;
}
}
return i;
}
int main()
{
STREC s[N]={{"GA05",85},{"GA03",76},{"GA02",69},{"GA04",85},{"GA01",91},
{"GA07",72},{"GA08",64},{"GA09",64},{"GA10",85},{"GA06",64}};
STREC h[N];
int i,n;
n=fun(s,h);
printf("The %d lowest score:\n",n);
for(i=0;i<n;i++)
printf("%s  %4d\n",h[i].num,h[i].s);
printf("\n");
}

温馨提示:答案为网友推荐,仅供参考
相似回答