user-0 提问: c语言结构体题目

回复:
user: user-0
content: 引用 4 楼 自信男孩的回复:#include <stdio.h>  #define N 3  struct Student {     int num;      char name[10];     float score[3];     float aver; };  int main() {     int i;      struct Student stu[N];      struct Student *p=stu;      void average(struct Student stu[N]);      for(i=0;i<N;i++)     {         scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i]. score[0],&stu[i].score[1],&stu[i].score[2]);         //stu[i].aver= (stu[i].score[0]+ stu[i]. score[1]+ stu[i].score[2])/3;         stu[i].aver= (stu[i].score[0]+ stu[i]. score[1]+ stu[i].score[2])/3.0;     }     average(p);     return 0; }  void average(struct Student stu[N]) {     int i,j,k,max[3];     float sum,           aver[3];      for(i=0;i<3;i++) {         sum = 0;         max[i] = 0;         for(j=0;j<N;j++) {             sum += stu[j].score[i];             if (stu[j].score[i] > stu[max[i]].score[i])                 max[i] = j;         }         aver[i]=sum / 3.0;     }     /*     for(i=0;i<3;i++)     {         sum=0;          for(j=0;j<N;j++)         {             sum+=stu[j].score[i];              for(k=1;k<N;k++)             {                 if(stu[j].score[i]<stu[k].score[i])                 {                     max[i]=k;                 }             }         }         aver[i]=sum/3;     }     */     for(i=0;i<3;i++)     {         printf("%d %5.1f\n%5d %s %5.1f %5.1f %5.1f %5.1f\n",i,aver[i],max[i],stu[max[i]].name,                  stu[max[i]].score[0],stu[max[i]].score[1],stu[max[i]].                  score[2],stu[max[i]].aver);     } } 供参考～  对比代码找一下自己的问题～ 万分感谢

user: user-1
content: #include <stdio.h>  #define N 3  struct Student {     int num;      char name[10];     float score[3];     float aver; };  int main() {     int i;      struct Student stu[N];      struct Student *p=stu;      void average(struct Student stu[N]);      for(i=0;i<N;i++)     {         scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i]. score[0],&stu[i].score[1],&stu[i].score[2]);         //stu[i].aver= (stu[i].score[0]+ stu[i]. score[1]+ stu[i].score[2])/3;         stu[i].aver= (stu[i].score[0]+ stu[i]. score[1]+ stu[i].score[2])/3.0;     }     average(p);     return 0; }  void average(struct Student stu[N]) {     int i,j,k,max[3];     float sum,           aver[3];      for(i=0;i<3;i++) {         sum = 0;         max[i] = 0;         for(j=0;j<N;j++) {             sum += stu[j].score[i];             if (stu[j].score[i] > stu[max[i]].score[i])                 max[i] = j;         }         aver[i]=sum / 3.0;     }     /*     for(i=0;i<3;i++)     {         sum=0;          for(j=0;j<N;j++)         {             sum+=stu[j].score[i];              for(k=1;k<N;k++)             {                 if(stu[j].score[i]<stu[k].score[i])                 {                     max[i]=k;                 }             }         }         aver[i]=sum/3;     }     */     for(i=0;i<3;i++)     {         printf("%d %5.1f\n%5d %s %5.1f %5.1f %5.1f %5.1f\n",i,aver[i],max[i],stu[max[i]].name,                  stu[max[i]].score[0],stu[max[i]].score[1],stu[max[i]].                  score[2],stu[max[i]].aver);     } } 供参考～  对比代码找一下自己的问题～

user: user-0
content: 那个那里错了，能不能帮忙看一下，结果不太对

user: user-0
content: #include <stdio.h>  #define N 10  struct Student { int num;  char name[10]; float score[3]; float aver; }; int main() { int i;  struct Student stu[N];  struct Student *p=stu;  void average(struct Student stu[N]); for(i=0;i<N;i++) { scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i]. score[0],&stu[i].score[1],&stu[i].score[2]); stu[i].aver= (stu[i].score[0]+ stu[i]. score[1]+ stu[i].score[2])/3; } average(p); return 0; } void average(struct Student stu[N]) { int i,j,k,max[3]; float sum, aver[3]; for(i=0;i<3;i++) { sum=0;  for(j=0;j<N;j++) { sum+=stu[j].score[i]; max[i]=j;    for(k=1;k<N;k++)   {     if(stu[j].score[i]<stu[k].score[i]) 	{ 		max[i]=k; 	}   } } aver[i]=sum/3; } for(i=0;i<3;i++) { printf("%d %5.1f\n%5d %s %5.1f %5.1f %5.1f %5.1f\n",i,aver[i],max[i],stu[max[i]].name,  stu[max[i]].score[0],stu[max[i]].score[1],stu[max[i]].  score[2],stu[max[i]].aver); } }

user: user-1
content: 不要什么都不写，什么都不做，就让别人帮你写好，调试正确了。别人不一定这么闲，如果真想要，付费给别人吧～ 天上掉馅饼的事情想想就好，没那么多好事～ 现在想起来要交作业了，早干嘛去了？