当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年计算机等级考试二级C:50套上机题库(4)
发布时间:2010/9/13 16:51:20 来源:www.xue.net 编辑:城市总裁吧

  7、给定程序中,函数fun的功能是:将形参n中,各位上为偶数的数取出,并按原来从高位到低位的顺序组成一个新的数,并作为函数值返回。

  例如,从主函数输入一个整数:27638496,函数返回值为:26846。

  请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。

  注意:源程序存放在考生文件夹下的BLANK1.C中。

  不得增行或删行,也不得更改程序的结构!

  #include

  unsigned long fun(unsigned long n)

  { unsigned long x=0, s, i; int t;

  s=n;

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

  i=__1__;

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

  while(__2__)

  { t=s%10;

  if(t%2==0){

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

  x=x+t*i; i=__3__;

  }

  s=s/10;

  }

  return x;

  }

  main()

  { unsigned long n=-1;

  while(n>99999999||n<0)

  { printf("Please input(0

  printf("\nThe result is: %ld\n",fun(n));

  }

  8、给定程序中,函数fun的功能是:将a所指3×5矩阵中第k列的元素左移到第0列,第k列以后的每列元素行依次左移,原来左边的各列依次绕到右边。

  例如,有下列矩阵:

  1 2 3 4 5

  1 2 3 4 5

  1 2 3 4 5

  若k为2,程序执行结果为

  3 4 5 1 2

  3 4 5 1 2

  3 4 5 1 2

  请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。

  注意:源程序存放在考生文件夹下的BLANK1.C中。

  不得增行或删行,也不得更改程序的结构!

  #include

  #define M 3

  #define N 5

  void fun(int (*a)[N],int k)

  { int i,j,p,temp;

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

  for(p=1; p<= __1__; p++)

  for(i=0; i

  { temp=a[i][0];

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

  for(j=0; j< __2__ ; j++) a[i][j]=a[i][j+1];

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

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

  }

  }

  main( )

  { int x[M][N]={ {1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5} },i,j;

  printf("The array before moving:\n\n");

  for(i=0; i

  { for(j=0; j

  printf("\n");

  }

  fun(x,2);

  printf("The array after moving:\n\n");

  for(i=0; i

  { for(j=0; j

  printf("\n");

  }

  }

广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved