关于#C语言#的问题,如何解决?

学生的记录由学生姓名、学号、语文、数学、英语三门成绩组成,N名学生的数据已在主函数中放入结构体数组s中,
请编写函数fun,其功能是:把三门总分最低的学生数据放在h所指的数组中。注意:分数最低的学生可能不止一个,
函数返回分数最低的学生的人数。 注意:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
这是学校的问题以及我做的代码,跑学校的题目不通过,求各位看一下问题在哪

试题程序:*/

#include <stdio.h>
#include<stdlib.h> 
# define  N 6
typedef  struct
{ 
    char name[10];
    long num;
    int s1;
    int s2;
    int s3;
    int s;
} STREC;
int fun (STREC *a,STREC *b,int m)
{
  /***********Begin*************/
    int i,j=0;
    int min;
        for(i=0;i<N;i++){
        a[i].s=a[i].s1+a[i].s2+a[i].s3;    
        }
    min=a[0].s;
    for(i=0;i<N;i++){
            if(a[i].s<min){
            min=a[i].s;    }
        }
    for(i=0;i<N;i++){
        if(a[i].s==min){
            b[j++]=a[i];
        }
    }
    return j;



  /**********End***************/
}
int main()
{
  STREC s[100]={{"GA01",1,80,56,87},{"GA03",3,76,56,54},{"GA02",2,69,63,54},{"GA04",4,85,98,90},{"GA05",5,91,94,95},{"GA06",6,72,80,87}};
  STREC h[100]; 
  int i,n,m;  
  FILE *out,*in;
  n=fun(s,h,N);
  printf("The %d lowest score:\n",n);
  for(i=0;i<n;i++)
    printf("%s %4d\n",h[i].name,h[i].s);
  printf("\n");
  /******************************/
  in=fopen("in53.dat","r");
  out=fopen("out53.dat","w");
  fscanf(in,"%d\n",&m);
  for(i=0;i<m;i++)
    fscanf(in,"%s %ld %d %d %d\n",s[i].name,&s[i].num,&s[i].s1,&s[i].s2,&s[i].s3);
  n=fun(s,h,m);
  fprintf(out,"%d\n",n);
  for(i=0;i<n;i++)
      fprintf(out,"%s %d\n",h[i].name,h[i].s);
  fclose(in);
  fclose(out);
  /******************************/
  system("pause");
  return 0;
}


现在是没有实现你说功能吗?

  • 你可以参考下这个问题的回答, 看看是否对你有帮助, 链接: https://ask.csdn.net/questions/7489718
  • 除此之外, 这篇博客: 习题 8.15 有一个班4个学生,5门课程。1. 求第1门课程的平均分;2.找出有两门以上课程不及格的学生,输出他们的学号和全部课程成绩及平均成绩;3.找出平均成绩在90分以上或全部课程成绩在85分以中的 习题 8.15 有一个班4个学生,5门课程。1. 求第1门课程的平均分;2.找出有两门以上课程不及格的学生,输出他们的学号和全部课程成绩及平均成绩;3.找出平均成绩在90分以上或全部课程成绩在85分以上的学生。分别编3个函数实现以上3个要求。 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 代码块:

    #include <stdio.h>
    #include <stdlib.h>
    void aver_fcourse(int *s[4], int n);           //定义函数1
    void two_fail(int *s[4], int m, int n);        //定义函数2
    void high_score(int *s[4], int m, int n);      //定义函数3
    int main()
    {
        int *stu_score[4], i, j;
        for (i=0; i<4; i++){
            stu_score[i]=(int *)malloc(3*sizeof(int));                   //给学生成绩分配动态空间
            printf("Please enter No.%d student score: ", i+1);           //输入学生成绩
            for (j=0; j<5; scanf("%d", *(stu_score+i)+j), j++);
        }
        aver_fcourse(stu_score, 4);                                      //调用函数1
        two_fail(stu_score, 4, 5);                                       //调用函数2
        high_score(stu_score, 4, 5);                                     //调用函数3
        return 0;
    }
    //函数1
    void aver_fcourse(int *s[4], int n)
    {
        int i;
        float sum;
        for (i=0, sum=0; i<n; sum+=*s[i++]);
        printf("The first course average score: %.2f\n", sum/n);
    }
    //函数2
    void two_fail(int *s[4], int m, int n)
    {
        int i, j, k, cc;
        float sum;
        for (i=0; i<m; i++){
            for (j=0, cc=0; j<n; *(*(s+i)+j)<60 ? cc++, j++ : j++);
            if (cc>=2){
                printf("No.%d student is fail.  Score: ", i+1);
                for (k=0, sum=0; k<n; printf("%d ", *(*(s+i)+k)), sum+=*(*(s+i)+k), k++);
                printf("\nAverage=%.2f\n", sum/n);
            }
        }
    }
    //函数3
    void high_score(int *s[4], int m, int n)
    {
        int i, j, cc;
        float sum, aver;
        for (i=0; i<m; i++){
            for (j=0, cc=0, sum=0; j<n; sum+=*(*(s+i)+j), *(*(s+i)+j)>85 ? cc++, j++ : j++);
            aver=sum/n;
            if (aver>90||cc==5)
                printf("No.%d student is high score.\n", i+1);
        }
    }