已知学生的记录是由学号和学习成绩构成,N名学生的数据已存入a机构体数组中。 请编写函数fun,该函数的功能是:找出成绩最高的学生记录,通过形参返回主函数(规定只有一个最高分)

/已知学生的记录是由学号和学习成绩构成,N名学生的数据已存入a机构体数组中。
请编写函数fun,该函数的功能是:找出成绩最高的学生记录,通过形参返回主函数(规定只有一个最高分)
/

#include <stdio.h>
#include <string.h>
typedef struct student
{
    int stu_id;
    int score;
}stu;
void fun(stu *a,stu *str, int n)
{
    *str=a[0];
    for(int i=0;i<n;i++)
    {
        if(a[i].score > (*str).score)
        {
            *str=a[i];
        }
    }
}
int main(void)
{
    stu a[100],str;
    int n=0;
    printf("please enter student pople\n");
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        printf("please enter %d student id score\n",i+1);
        scanf("%d %d",&a[i].stu_id,&a[i].score);
    }
    fun(a,&str,n);
    printf("id:%d score:%d\n",str.stu_id,str.score);
    return 0;
}

posted on 2024-06-27 23:18  wessf  阅读(38)  评论(0)    收藏  举报