鱼C论坛

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

[已解决]结构体问题

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

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

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

x
  1. #include <stdio.h>
  2. struct subjects
  3. {
  4.      int Math;
  5.          int Physic;
  6.          int English;
  7. };

  8. typedef struct subjects subjects;


  9. int main()
  10. {
  11.     int num;
  12.         struct Student
  13.         {
  14.            int ID;
  15.            char name[20];
  16.            int subjects;
  17.            int ave;
  18.         };
  19.         typedef struct Student Student;
  20.        
  21.         void Dealing( int n , Student *stu1 );

  22.         Student stu[10];

  23.         scanf("%d",&num);

  24.         Dealing(num,stu);



  25. }

  26. void Dealing( int n , Student *stu1 )
  27. {
  28.     int i,Ave;
  29.         for(i=0;i<n;i++)
  30.         {
  31.                 scanf("%d%s%d%d%d",&stu[i].ID,stu[i].name,&stu[i].subjects.Math,&stu[i].subjects.Physic,&stu[i].subjects.English);
  32.                 Ave = (stu[i].subjects.Physic + stu[i].subjects.English +stu[i].subjects.Math)/3.0;
  33.                 stu[i].ave=Ave;
  34.         }
  35. }
复制代码



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

  2. struct subjects
  3. {
  4.     int Math;
  5.     int Physic;
  6.     int English;
  7. };

  8. typedef struct subjects subjects;

  9. struct Student
  10. {
  11.     int ID;
  12.     char name[20];
  13.     //int subjects;
  14.     subjects subjects;
  15.     int ave;
  16. };
  17. typedef struct Student Student;

  18. int main()
  19. {
  20.     int num;

  21.     void Dealing( int n , Student *stu1 );

  22.     Student stu[10];

  23.     scanf("%d",&num);

  24.     Dealing(num,stu);


  25.     return 0;
  26. }

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

使用道具 举报

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

  2. struct subjects
  3. {
  4.     int Math;
  5.     int Physic;
  6.     int English;
  7. };

  8. typedef struct subjects subjects;

  9. struct Student
  10. {
  11.     int ID;
  12.     char name[20];
  13.     //int subjects;
  14.     subjects subjects;
  15.     int ave;
  16. };
  17. typedef struct Student Student;

  18. int main()
  19. {
  20.     int num;

  21.     void Dealing( int n , Student *stu1 );

  22.     Student stu[10];

  23.     scanf("%d",&num);

  24.     Dealing(num,stu);


  25.     return 0;
  26. }

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-25 15:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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