Lansional 2022-11-19 13:44 采纳率: 91.5%
浏览 13
已结题

有n个结构体变量,内含学生号、姓名和3门课程的成绩。要求输出平均成绩最高的学生的信息

问题遇到的现象和发生背景

有n个结构体变量,内含学生号、姓名和3门课程的成绩。要求输出平均成绩最高的学生的信息
想要知道错在哪

用代码块功能插入代码,请勿粘贴截图
#pragma warning(disable : 4996) 
#include<stdio.h>
#define N 3             //三个学生

struct Student
{
    int num;
    char name[10];        
    float score[3];      //三门课程
    double aver;
};

int main()
{
    void input(struct Student s1[]);
    struct Student max(struct Student s2[]);
    void print(struct Student st);
    struct Student stu[N];
    struct Student* p;
    struct Student pt;
    p = stu;
    input(p);
    pt = max(p);
    print(pt);
    return 0;
}

void input(struct Student s1[])     
{
    int i;
    printf("输入3位学生的信息:\n");
    for (i = 0; i < N; i++)
    {
        scanf("%d %s %f %f %f\n", &s1[i].num, &s1[i].name, &s1[i].score[0], &s1[i].score[1], &s1[i].score[2]);  //输入各学生的信息
        s1[i].aver = s1[i].score[0] + s1[i].score[1] + s1[i].score[2] / 3.0;         //计算各学生的平均成绩
    }
}

struct Student max(struct Student s2[])         //找出平均成绩最高的学生
{
    int i;
    int m = 0;
    for (i = 0; i < N; i++)
    {
        if (s2[i].aver > s2[m].aver)
        {
            m = i;                       
        }
    }
    return (s2[m]);
}

void print(struct Student st)      //输出平均成绩最高的学生
{
    printf("平均成绩最高的学生是:\n");
    printf("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n", st.num, st.name, st.score[0], st.score[1], st.score[2],st.aver);
}

运行结果及报错内容

只有一个警告:返回值被忽略:scanf
我输入3个学生信息后,系统不输出平均成绩最高的学生

  • 写回答

1条回答 默认 最新

报告相同问题?

问题事件

  • 系统已结题 11月27日
  • 已采纳回答 11月19日
  • 创建了问题 11月19日

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大