黯落辰星 2022-04-05 19:19 采纳率: 85%
浏览 180
已结题

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

#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;

}

  • 写回答

2条回答 默认 最新

  • CSDN专家-link 2022-04-05 19:36
    关注
    #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;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月13日
  • 已采纳回答 4月5日
  • 创建了问题 4月5日

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?