鱼C论坛

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

结构数组

[复制链接]
发表于 2019-12-1 11:31:55 From FishC Mobile | 显示全部楼层 |阅读模式
5鱼币
这个怎么写大佬们



/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------

题目:学生记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组中,请
      编写函数fun,其功能是:把分数最低的学生数据放入b所指的数组中,注意:分数
      最低的学生可能不止一个,函数返回分数最低的学生人数。

注意:请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入
      你编写的若干语句。

-------------------------------------------------------*/
#include <stdio.h>

#define   N   16

void wwjt ();

typedef  struct
{  
        char  num[10];
        int   s;
} STREC;
int  fun( STREC  *a, STREC *b )
{
        /**********Program**********/


        /**********  End  **********/
}

void main()
{  
        STREC  s[N]={{"GA05",85},{"GA03",76},{"GA02",69},{"GA04",85},
                {"GA01",91},{"GA07",72},{"GA08",64},{"GA06",87},
                {"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},
                {"GA011",91},{"GA017",64},{"GA018",64},{"GA016",72}};
        STREC  h[N];
        int  i,n;
        n=fun( s,h );
        printf("The %d lowest score :\n",n);
        for(i=0;i<n; i++)
                printf("%s  %4d\n",h[i].num,h[i].s);
        printf("\n");
        wwjt ( );

}
void wwjt ( )
{
        FILE *in,*out ;
        int  i,n,a;
        STREC  s[N];
        STREC  h[N];
        in=fopen("in.dat","r");
        if(in==NULL)
        {
                printf("Please Verify The Currernt Dir..It May Be Changed");
        }
        out=fopen("out.dat","w");
        if(out==NULL)
        {
                printf("Please Verify The Current Dir.. It May Be Changed");
        }
        for(a=0;a<10;a++)
        {
                for(i=0;i<16;i++)
                {
                        fscanf(in,"%s %d",&s[i].num,&s[i].s);
                }
                n=fun( s,h );
                fprintf(out, "%d\n",n);
                for(i=0;i<n; i++)
                        fprintf(out, "%4d\n",h[i].s);
        }
        fclose(in);
        fclose(out);
}

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-12-1 23:43:07 | 显示全部楼层
  1. int  fun(STREC  *a, STREC *b)
  2. {
  3.     /**********Program**********/

  4.     int i, j, score;
  5.     for (score = a[0].s, i = 1; i < N; i++) {
  6.         if (a[i].s < score)
  7.             score = a[i].s;
  8.     }
  9.     for (i = 0, j = 0; i < N; i++) {
  10.         if (a[i].s == score) {
  11.             b[j++] = a[i];
  12.         }
  13.     }
  14.     return j;

  15.     /**********  End  **********/
  16. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-4 01:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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