#include
#defineN12
typedefstruct
{
charnum [10];
doubles;
}STREC;
doublefun( STREC*a,STREC*b,int*n )
{
int i,c=0;
double avar=0.0;
for(i=0;i=avar)
b[c++]=a;//这里的a为什么不是a.s??
*n=c;
return avar;
}
main ()
{
STRECs[N]={{"GA05",85}, {"GA03",76}, {"GA02",69}, {"GA04",85},
{"GA01",91}, {"GA07",72}, {"GA08",64}, {"GA06",87},
{"GA09",60}, {"GA11",79}, {"GA12",73}, {"GA10",90}};
STRECh [N], t;
FILE*out ;
inti,j,n;
doubleave;
ave=fun ( s, h, &n );
printf ( "The %d student data which is higher than %7.3f:\n", n, ave);
for ( i=0; i<n; i++ )
printf("%s%4.1f\n", h. num, h. s);
printf ("\n");
out=fopen("out.dat","w");
fprintf(out,"%d\n%7.3f\n", n, ave);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(h.s<h[j].s)
{
t=h ;
h=h[j];
h[j]=t;
}
for(i=0;i<n; i++)
fprintf(out, "%4.1f\n",h.s);
fclose(out);
}
|