结构数组
这个怎么写大佬们/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:学生记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组中,请
编写函数fun,其功能是:把分数最低的学生数据放入b所指的数组中,注意:分数
最低的学生可能不止一个,函数返回分数最低的学生人数。
注意:请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入
你编写的若干语句。
-------------------------------------------------------*/
#include <stdio.h>
#define N 16
void wwjt ();
typedefstruct
{
charnum;
int s;
} STREC;
intfun( STREC*a, STREC *b )
{
/**********Program**********/
/**********End**********/
}
void main()
{
STRECs={{"GA05",85},{"GA03",76},{"GA02",69},{"GA04",85},
{"GA01",91},{"GA07",72},{"GA08",64},{"GA06",87},
{"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},
{"GA011",91},{"GA017",64},{"GA018",64},{"GA016",72}};
STRECh;
inti,n;
n=fun( s,h );
printf("The %d lowest score :\n",n);
for(i=0;i<n; i++)
printf("%s%4d\n",h.num,h.s);
printf("\n");
wwjt ( );
}
void wwjt ( )
{
FILE *in,*out ;
inti,n,a;
STRECs;
STRECh;
in=fopen("in.dat","r");
if(in==NULL)
{
printf("Please Verify The Currernt Dir..It May Be Changed");
}
out=fopen("out.dat","w");
if(out==NULL)
{
printf("Please Verify The Current Dir.. It May Be Changed");
}
for(a=0;a<10;a++)
{
for(i=0;i<16;i++)
{
fscanf(in,"%s %d",&s.num,&s.s);
}
n=fun( s,h );
fprintf(out, "%d\n",n);
for(i=0;i<n; i++)
fprintf(out, "%4d\n",h.s);
}
fclose(in);
fclose(out);
}
intfun(STREC*a, STREC *b)
{
/**********Program**********/
int i, j, score;
for (score = a.s, i = 1; i < N; i++) {
if (a.s < score)
score = a.s;
}
for (i = 0, j = 0; i < N; i++) {
if (a.s == score) {
b = a;
}
}
return j;
/**********End**********/
}
页:
[1]