正确的应输出最高最低分。以文本形式建立初始数据文件,文件名为,file1.dat,请输入十个学生的学号,姓名及考试成绩,读入file1.dat中的数据,输出最高分与最低分

img

img

img


#include <stdio.h>
#include <stdlib.h>
#define N 10
struct student
{
int num;
char name[20];
int score;
};
int main()
{
int i;
student st,stmax,stmin;
FILE *fp;
stmax.score=0;
stmin.score=100;
fp=fopen("file1.dat","r");
if(!fp)
exit(0);
for(i=0;i<N;i++)
{
fscanf(fp,"%d %s %d",&st.num,st.name,&st.score);
if(st.score>stmax.score)
stmax=st;
if(st.score<stmin.score)
stmin=st;
}
fclose(fp);
printf("high:%5d%15s%5d\n",stmax.num,stmax.name,stmax.score);
printf("low:%5d%15s%5d\n",stmin.num,stmin.name,stmin.score);
return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define N 10
struct student
{
    int num;
    char name[20];
    int score;
};
int main()
{
    int i;
    student st, stmax, stmin;
    FILE* fp;
    stmax.score = 0;
    stmin.score = 100;
    fp = fopen("file1.dat", "r");
    if (!fp)
        exit(0);
    for (i = 0; i < N; i++)
    {
        fscanf(fp, "%d %s %d", &st.num, st.name, &st.score);
        if (st.score > stmax.score)
            stmax = st;
        if (st.score < stmin.score)
            stmin = st;
    }
    fclose(fp);
    printf("high:%5d%15s%5d\n", stmax.num, stmax.name, stmax.score);
    printf("low:%5d%15s%5d\n", stmin.num, stmin.name, stmin.score);
    return 0;
}