鱼C论坛

 找回密码
 立即注册
查看: 1376|回复: 1

[已解决]结构体问题

[复制链接]
发表于 2021-6-20 11:37:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <stdio.h>
struct subjects
{
     int Math;
         int Physic;
         int English;
};

typedef struct subjects subjects;


int main()
{
    int num;
        struct Student
        {
           int ID;
           char name[20];
           int subjects;
           int ave;
        };
        typedef struct Student Student;
        
        void Dealing( int n , Student *stu1 );

        Student stu[10];

        scanf("%d",&num);

        Dealing(num,stu);



}

void Dealing( int n , Student *stu1 )
{
    int i,Ave;
        for(i=0;i<n;i++)
        {
                scanf("%d%s%d%d%d",&stu[i].ID,stu[i].name,&stu[i].subjects.Math,&stu[i].subjects.Physic,&stu[i].subjects.English);
                Ave = (stu[i].subjects.Physic + stu[i].subjects.English +stu[i].subjects.Math)/3.0;
                stu[i].ave=Ave;
        }
}


大体思路就是用结构体存放数据,但是格式有问题,不知道哪里出了问题,请帮忙看一下
最佳答案
2021-6-20 11:45:25
#include <stdio.h>

struct subjects
{
    int Math;
    int Physic;
    int English;
};

typedef struct subjects subjects;

struct Student
{
    int ID;
    char name[20];
    //int subjects;
    subjects subjects;
    int ave;
};
typedef struct Student Student;

int main()
{
    int num;

    void Dealing( int n , Student *stu1 );

    Student stu[10];

    scanf("%d",&num);

    Dealing(num,stu);


    return 0;
}

void Dealing( int n , Student *stu1 )
{
    int i,Ave;
    for(i=0;i<n;i++)
    {
        scanf("%d%s%d%d%d",&stu1[i].ID,stu1[i].name,&stu1[i].subjects.Math,&stu1[i].subjects.Physic,&stu1[i].subjects.English);
        Ave = (stu1[i].subjects.Physic + stu1[i].subjects.English +stu1[i].subjects.Math)/3.0;
        stu1[i].ave=Ave;
    }
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-20 11:45:25 | 显示全部楼层    本楼为最佳答案   
#include <stdio.h>

struct subjects
{
    int Math;
    int Physic;
    int English;
};

typedef struct subjects subjects;

struct Student
{
    int ID;
    char name[20];
    //int subjects;
    subjects subjects;
    int ave;
};
typedef struct Student Student;

int main()
{
    int num;

    void Dealing( int n , Student *stu1 );

    Student stu[10];

    scanf("%d",&num);

    Dealing(num,stu);


    return 0;
}

void Dealing( int n , Student *stu1 )
{
    int i,Ave;
    for(i=0;i<n;i++)
    {
        scanf("%d%s%d%d%d",&stu1[i].ID,stu1[i].name,&stu1[i].subjects.Math,&stu1[i].subjects.Physic,&stu1[i].subjects.English);
        Ave = (stu1[i].subjects.Physic + stu1[i].subjects.English +stu1[i].subjects.Math)/3.0;
        stu1[i].ave=Ave;
    }
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-21 14:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表