为什么无法输出呐?它可以编译跑起来,但无法输出。


#include<stdio.h>
struct student
    {
        int xuehao;
        char name[30];
        float fen1;
        float fen2;
    }sheng[5];
int main()
{
    
    struct student max(struct student a[]);
    struct student zuida;
    int i;
    for (i = 0; i <= 4; i++)
    {
        printf("请输入%d名学生学号,姓名,和两门成绩:\n", i + 1);
        scanf_s("%d %s %f %f", &sheng[i].xuehao, sheng[i].name, &sheng[i].fen1, &sheng[i].fen2);
    }
    zuida = max(sheng);
    printf("平均分最高的学生情况如下:\n");
    printf("学号%d\n姓名%s\n2门成绩%f%f\n", zuida.xuehao, zuida.name, zuida.fen1, zuida.fen2);
    return 0;
}
    struct student max(struct student a[])
    {
        float pinjunfen[5];
        int i, zuigao;
        for (i = 0; i <= 4; i++)
            pinjunfen[i] = (a[1].fen1 + a[i].fen2) / 2;
        for (zuigao = 0, i = 0; i <= 4; i++)
            if (pinjunfen[zuigao] < pinjunfen[i])
                zuigao = i;
        return (a[zuigao]);
    }

img

修改如下,供参考:

#include<stdio.h>
struct student
{
    int xuehao;
    char name[30];
    float fen1;
    float fen2;
}sheng[5];
int main()
{
    struct student max(struct student a[]);
    struct student zuida;
    int i;
    for (i = 0; i <= 4; i++)
    {
        printf("请输入%d名学生学号,姓名,和两门成绩:\n", i + 1);
        scanf_s("%d %s %f %f", &sheng[i].xuehao, sheng[i].name,20, &sheng[i].fen1, &sheng[i].fen2);
        //canf_s("%d %s %f %f", &sheng[i].xuehao, sheng[i].name, &sheng[i].fen1, &sheng[i].fen2);
    }
    zuida = max(sheng);
    printf("平均分最高的学生情况如下:\n");
    printf("学号%d\n姓名%s\n2门成绩%f%f\n", zuida.xuehao, zuida.name, zuida.fen1, zuida.fen2);
    return 0;
}
struct student max(struct student a[])
{
    float pinjunfen[5];
    int i, zuigao;
    for (i = 0; i <= 4; i++)
        pinjunfen[i] = (a[i].fen1 + a[i].fen2) / 2;//pinjunfen[i] = (a[1].fen1 + a[i].fen2) / 2;
    for (zuigao = 0, i = 0; i <= 4; i++)
        if (pinjunfen[zuigao] < pinjunfen[i])
            zuigao = i;
    return (a[zuigao]);
}

我看了一下,应该是没问题的
#include<stdio.h>
struct student
{
int xuehao;
char name[30];
float fen1;
float fen2;
}sheng[5];
struct student max(struct student []);
int main()
{
struct student max(struct student a[]);
struct student zuida;
int i;
for (i = 0; i <= 4; i++)
{
printf("请输入%d名学生学号,姓名,和两门成绩:\n", i + 1);
scanf("%d %s %f %f", &sheng[i].xuehao, sheng[i].name, &sheng[i].fen1, &sheng[i].fen2);
}
zuida = max(sheng);
printf("平均分最高的学生情况如下:\n");
printf("学号%d\n姓名%s\n2门成绩%f,%f\n", zuida.xuehao, zuida.name, zuida.fen1, zuida.fen2);
return 0;
}
struct student max(struct student a[])
{
float pinjunfen[5];
int i, zuigao;
for (i = 0; i <= 4; i++)
pinjunfen[i] = (a[1].fen1 + a[i].fen2) / 2;
for (zuigao = 0, i = 0; i <= 4; i++)
if (pinjunfen[zuigao] < pinjunfen[i])
zuigao = i;
return (a[zuigao]);
}
如还有问题,就照我的代码写吧
(注:你这是C语言,不是C++)