全国计算机二级考试内容填空.docx

上传人:b****5 文档编号:5936303 上传时间:2023-01-02 格式:DOCX 页数:53 大小:34.25KB
下载 相关 举报
全国计算机二级考试内容填空.docx_第1页
第1页 / 共53页
全国计算机二级考试内容填空.docx_第2页
第2页 / 共53页
全国计算机二级考试内容填空.docx_第3页
第3页 / 共53页
全国计算机二级考试内容填空.docx_第4页
第4页 / 共53页
全国计算机二级考试内容填空.docx_第5页
第5页 / 共53页
点击查看更多>>
下载资源
资源描述

全国计算机二级考试内容填空.docx

《全国计算机二级考试内容填空.docx》由会员分享,可在线阅读,更多相关《全国计算机二级考试内容填空.docx(53页珍藏版)》请在冰豆网上搜索。

全国计算机二级考试内容填空.docx

全国计算机二级考试内容填空

内容填空:

1、给定程序中,函数fun的功能是:

在任意给定的9个正整数中找出按升序排列时处于中间的数,将原数据序列中比该中间数小的数用该中间数替换,位置不变,在主函数中输出处理后的数据序列,并将中间数作为函数值返回。

  例如,有9个正整数:

1  5  7  23  87  5  8  21  45

  按升序排列时的中间数为:

8

  处理后主函数中输出的数列为:

8  8  8  23  87  8  8  21  45

  #include  

  #define    N    9

  int fun(int  x[])

  {  int  i,j,k,t,mid,b[N];

     for(i=0;i

     for(i=0;i<=N/2;i++)

     {  k=i;

        for(j=i+1;jb[j])  k=j;

        if(k !

= i )

        {  

  /**********found**********/

          t=b[i]; b[i]=___1___; b[k]=t;

        }

     }

  /**********found**********/

     mid=b[___2___];

     for(i=0; i

  /**********found**********/

       if(x[i] ___3___ mid) x[i]=mid;

     return  mid;

  }

  main()

  {  int  i, x[N]={1,5,7,23,87,5,8,21,45};

     for(i=0; i

     printf("\nThe mid data is:

 %d\n",fun(x));

     for(i=0; i

     printf("\n");

  }

2、给定程序中,函数fun的功能是建立一个N×N的矩阵。

 矩阵元素的构成规律是:

最外层元素的值全部为1;从外向内第2层元素的值全部为2;第3层元素的值全部为3,…依次类推。

例如,若N=5,生成的矩阵为:

      1    1    1    1    1

      1    2    2    2    1

      1    2    3    2    1

      1    2    2    2    1

      1    1    1    1    1

  #include  

  #define   N   7

  /**********found**********/

  void fun(int  (*a) __1__)

  { int  i,j,k,m;

    if(N%2==0) m=N/2 ;

    else       m=N/2+1;

    for(i=0; i

  /**********found**********/

       for(j= __2__ ; j

          a[i][j]=a[N-i-1][j]=i+1;

       for(k=i+1; k

  /**********found**********/

          a[k][i]=a[k][N-i-1]= __3__;

    }

  }

  main()

  { int  x[N][N]={0},i,j;

    fun(x);

    printf("\nThe result is:

\n");

    for(i=0; i

    {  for(j=0; j

 3、给定程序中,函数fun的功能是:

 将s所指字符串中的所有数字字符移到所有非数字字符之后,并保持数字字符串和非数字字符串原有的先后次序。

例如,形参s所指的字符串为:

def35adh3kjsdf7。

执行结果为:

defadhkjsdf3537。

  #include    

  void fun(char  *s)

  {  int  i, j=0, k=0;    char  t1[80], t2[80];

     for(i=0; s[i]!

=’\0’; i++)

       if(s[i]>=’0’ && s[i]<=’9’)

       {

  /**********found**********/

         t2[j]=s[i]; ___1___;

       }

       else  t1[k++]=s[i];

    t2[j]=0;  t1[k]=0;

  /**********found**********/

    for(i=0; i

  /**********found**********/

    for(i=0; i<___3___; i++)  s[k+i]=t2[i];

  }

  main()

  {  char  s[80]="def35adh3kjsdf7";

     printf("\nThe original string is :

  %s\n",s);

     fun(s);

     printf("\nThe result is :

  %s\n",s);

  }

4、给定程序中,函数fun的功能是:

有N×N矩阵,以主对角线为对称线,对称元素相加并将结果存放在左下三角元素中,右上三角元素置为0。

例如,若N=3,有下列矩阵:

          1    2    3

          4    5    6

          7    8    9计算结果为

          1    0    0

          6    5    0

          10   14   9

  #include    

  #define    N    4

  /**********found**********/

  void fun(int  (*t)___1___ )

  {  int  i, j;

     for(i=1; i

     {  for(j=0; j

        {

  /**********found**********/

           ___2___ =t[i][j]+t[j][i];

  /**********found**********/

           ___3___ =0;

        }

     }

  }

  main()

  {  int  t[][N]={21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10}, i, j;

     printf("\nThe original array:

\n");

     for(i=0; i

     {  for(j=0; j

        printf("\n");

     }

     fun(t);

     printf("\nThe result is:

\n");

     for(i=0; i

     {  for(j=0; j

        printf("\n");

     }

  }

 5、给定程序中,函数fun的功能是:

对形参s所指字符串中下标为奇数的字符按ASCII码大小递增排序,并将排序后下标为奇数的字符取出,存入形参p所指字符数组中,形成一个新串。

  例如,形参s所指的字符串为:

baawrskjghzlicda,执行后p所指字符数组中的字符串应为:

aachjlsw。

  #include    

  void fun(char  *s, char  *p)

  {  int  i, j, n, x, t;

     n=0;

     for(i=0; s[i]!

=’\0’; i++)  n++;

     for(i=1; i

  /**********found**********/

        ___1___;

  /**********found**********/

        for(j=___2___+2 ; j

          if(s[t]>s[j]) t=j;

        if(t!

=i)

        {  x=s[i]; s[i]=s[t]; s[t]=x; }

     }

     for(i=1,j=0; i

  /**********found**********/

     p[j]=___3___;

  }

  main()

  {  char  s[80]="baawrskjghzlicda", p[50];

     printf("\nThe original string is :

  %s\n",s);

     fun(s,p);

     printf("\nThe result is :

  %s\n",p);

  }

 6、程序通过定义并赋初值的方式,利用结构体变量存储了一名学生的信息。

函数fun的功能是输出这位学生的信息。

  #include     

  typedef  struct

  {  int  num;

     char  name[9];

     char  sex;

     struct { int  year,month,day ;} birthday;

     float  score[3];

  }STU;

  /**********found**********/

  void show(STU  ___1___)

  {  int  i;

     printf("\n%d %s %c %d-%d-%d", tt.num, tt.name, tt.sex,

               tt.birthday.year, tt.birthday.month, tt.birthday.day);

    for(i=0; i<3; i++)

  /**********found**********/

       printf("%5.1f", ___2___);

    printf("\n");

  }

  main( )

  {  STU  std={ 1,"Zhanghua",’M’,1961,10,8,76.5,78.0,82.0 };

     printf("\nA student data:

\n");

  /**********found**********/

     show(___3___);

  }

 7、给定程序中,函数fun的功能是:

计算N×N矩阵的主对角线元素和反向对角线元素之和,并作为函数值返回。

注意:

要求先累加主对角线元素中的值,然后累加反向对角线元素中的值。

例如,若N=3,有下列矩阵:

          1    2    3

          4    5    6

          7    8    9

  fun函数首先累加1、5、9,然后累加3、5、7,函数的返回值为30。

  #include    

  #define    N    4

  fun(int  t[][N], int  n)

  {  int  i, sum;

  /**********found**********/

     ___1___;

     for(i=0; i

  /**********found**********/

       sum+=___2___ ;

     for(i=0; i

  /**********found**********/

       sum+= t[i][n-i-___3___] ;

     return sum;

  }

  main()

  {  int  t[][N]={21,2,13,24,25,16,47,38,29,11,32,54,42,21,3,10},i,j;

     printf("\nThe original data:

\n");

     for(i=0; i

     {  for(j=0; j

        printf("\n");

     }

     printf("The result is:

  %d",fun(t,N));

  }

8、给定程序中,函数fun的功能是:

计算形参x所指数组中N个数的平均值(规定所有数均为正数),作为函数值返回;并将大于平均值的数放在形参y所指数组中,在主函数中输出。

  例如,有10个正数:

46  30  32  40  6  17  45  15  48  26,平均值为:

30.500000

  主函数中输出:

46  32  40  45  48

  #include 

  #include 

  #define   N   10

  double fun(double  x[],double  *y)

  { int  i,j;    double  av;

  /**********found**********/

    av=__1__;

  /**********found**********/

    for(i=0; i

    for(i=j=0; i

  /**********found**********/

      if(x[i]>av)  y[__3__]= x[i];

    y[j]=-1;

    return  av;

  }

  main()

  { int  i;    double  x[N] = {46,30,32,40,6,17,45,15,48,26};

    double  y[N];

    for(i=0; i

    printf("\n");

    printf("\nThe average is:

 %f\n",fun(x,y));

    for(i=0; y[i]>=0; i++)  printf("%5.0f ",y[i]);

    printf("\n");

  }

 9、给定程序中,函数fun的功能是:

计算形参x所指数组中N个数的平均值(规定所有数均为正数),将所指数组中小于平均值的数据移至数组的前部,大于等于平均值的数据移至x所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。

  例如,有10个正数:

46  30  32  40  6  17  45  15  48  26,平均值为:

30.500000

  移动后的输出为:

30  6  17  15  26  46  32  40  45  48

  #include  

  #include  

  #define   N   10

  double fun(double  *x)

  { int  i, j;    double  av, y[N];

    av=0;

  /**********found**********/

    for(i=0; i

    for(i=j=0; i

      if( x[i]

  /**********found**********/

        y[j]=x[i]; x[i]=-1; __2__;}

    i=0;

    while(i

    {  if( x[i]!

= -1 ) y[j++]=x[i];

  /**********found**********/

       __3__;

    }

    for(i=0; i

    return  av;

  }

  main()

  { int  i;     double  x[N];

    for(i=0; i

    printf("\n");

    printf("\nThe average is:

 %f\n",fun(x));

    printf("\nThe result :

\n",fun(x));

    for(i=0; i

    printf("\n");

  }

10、给定程序中,函数fun的功能是:

计算形参x所指数组中N个数的平均值(规定所有数均为正数),将所指数组中大于平均值的数据移至数组的前部,小于等于平均值的数据移至x所指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。

  例如,有10个正数:

46  30  32  40  6  17  45  15  48  26,平均值为:

30.500000

  移动后的输出为:

46  32  40  45  48  30  6  17  15  26

  #include  

  #include  

  #define   N   10

  double fun(double  *x)

  { int  i, j;    double  s, av, y[N];

    s=0;

    for(i=0; i

  /**********found**********/

    av=__1__;

    for(i=j=0; i

      if( x[i]>av ){

  /**********found**********/

        y[__2__]=x[i]; x[i]=-1;}

    for(i=0; i

  /**********found**********/

      if( x[i]!

= __3__) y[j++]=x[i];

    for(i=0; i

    return  av;

  }

  main()

  { int  i;     double  x[N]= {46,30,32,40,6,17,45,15,48,26};

    for(i=0; i

    printf("\n");

    printf("\nThe average is:

 %f\n",fun(x));

    printf("\nThe result :

\n",fun(x));

    for(i=0; i

    printf("\n");

  }

11、函数fun的功能是:

把形参a所指数组中的奇数按原顺序依次存放到a[0]、a[1]、a[2]、……中,把偶数从数组中删除,奇数个数通过函数值返回。

例如:

若a所指数组中的数据最初排列为:

9、1、4、2、3、6、5、8、7,删除偶数后a所指数组中的数据为:

9、1、3、5、7,返回值为5。

  #include    

  #define    N    9

  int fun(int  a[], int  n)

  {  int  i,j;

     j = 0;

     for (i=0; i

  /**********found**********/

        if (a[i]%2==___1___)

        {

  /**********found**********/

          a[j] = a[i]; ___2___;

        }

  /**********found**********/

     return ___3___;

  }

  main()

  {  int  b[N]={9,1,4,2,3,6,5,8,7}, i, n;

     printf("\nThe original data  :

\n");

     for (i=0; i

     printf("\n");

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 农学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1