已知學生的記錄由學號和學習成績構成,M名學生的資料已存入a結構體陣列中,請撰寫函式fun,該函式的功能是:找出成績最高的學生記錄,通過形參回傳主函式(規定只有一個最高分),已給出函式的首部,請完成該函式,
請勿改動主函式main與其它函式中的任何內容,僅在函式fun的花括號中填入所撰寫的若干陳述句,
代碼如下:
#include<stdio.h>
#include<string.h>
#include<conio.h>
#define M 10
typedef struct ss
{
char num[10];
int s;
}SCORE;
void fun(SCORE a[],SCORE*s)
{
int i,max;
max=a[0].s;
for(i=0;i<M;i++)
if(a[i].s>max)
{
max=a[i].s;
*s=a[i];
}
}
main()
{
SCORE stu[M]={{"02",69},{"04",85},{"01",91},{"08",64},{"06",87},{"015",85},{"013",91},{"012",64},{"011",92},{"017",64}},n;
int i;
FILE*out;
printf("The original data:\n");
for(i=0;i<M;i++)
printf("N0=%s Mark=%d\n",stu[i].num,stu[i].s);
fun(stu,&n);
printf("THE RESULT:\n");
printf("The high:%s,%d\n",n.num,n.s);
out=fopen("outfile.dat","w");
fprintf(out,"%s\n%d",n.num,n.s);
fclose(out);
}
輸出運行視窗如下:

越努力越幸運!
加油,奧力給!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/244802.html
標籤:其他
