有三个学生的信息(包括学号和成绩)保存在主函数的结构体中,主函数调用函数以找出多个学生中成绩最大者的下标。

#include <stdio.h>

struct Student
{
char No[11];
int Score;
};

int FindMaxScore(struct Student stu[], int n);

int main(void)
{
struct Student stus[3] = {{"2008030201", 89}, {"2008030202", 92}, {"2008030203", 78}};
int k;

3printf("%s %d\n", stus[k].No, stus[k].Score);

return 0;

}

int FindMaxScore(3 分
)
{
int i, max, k=0;

max = stu[k].Score;    
for (i=1; i<n; i++)
{
    if (3

)
{
k = i;
max = stu[k].Score;
}
}

return k;

}

#include <stdio.h>

struct Student
{
    char No[11];
    int Score;
};

int FindMaxScore(struct Student stu[], int n);

int main(void)
{
    struct Student stus[3] = {{"2008030201", 89}, {"2008030202", 92}, {"2008030203", 78}};
    int k;

    k = FindMaxScore(stus,3);

    printf("%s %d\n", stus[k].No, stus[k].Score);
    return 0;
}

int FindMaxScore(struct Student stu[], int n)
{
    int i, max, k=0;

    max = stu[k].Score;    
    for (i=1; i<n; i++)
    {
        if (stu[i].Score > max)
        {
            k = i;
            max = stu[k].Score;
        }
    }
    return k;
}

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632