2016年计算机软考程序员模拟试题及答案2

时间:2016-07-19 14:49:00   来源:开云网页版     [字体: ]
试题四

  阅读下列函数说明和C函数,将应填入 n 处的字句写在答题纸的对应栏内。

  [函数2.1说明]

  函数strcat(char s[], char t[])的功能是:将字符串t复制连接字符串s的尾部,并返回新

  字符串的首地址作为函数值。例如:若s=“abcd”,t=“efg”,则新字符串应该是“abcdefg”。

  [函数2.1]

  char *strcat(char s[], char t[])

  { char *p;

  p = s + strlen(s)-1

  while( (1) ) {

  (2) ;

  }

  *p = ‘\0’;

  return s;

  }

  [函数2.2说明]

  函数f(char *str, char del)的功能是:将非空字符串str中的指定字符del删除,形成一个

  新字符串仍存放在str所指内存单元中。

  例如若str的值为“33123333435”,del的值为‘3’,调用此函数后,新字符串为:“1245”。

  [函数2.2]

  void f(char *str, char del)

  {

  int i, j, len;

  len=strlen(str);

  i=j=0;

  while(i  if ( (3) )

  (4) = str[i];

  i++;

  }

  (5) ;

  }

  试题五

  阅读以下说明和C代码,将应填入 n 处的字句写在答题纸的对应栏内。

  [说明]

  下面程序中函数fun的功能是:在含有10 个元素的s数组中查找数,及数所在位置 (即,下标值),数可能不止一个。数作为函数值返回,数的个数通过指针变量n传回,所在位置由数组pos传回。

  例如:

  若输入 2 8 5 7 8 4 5 3 2 8

  则应输出:

  The max: 8

  Total: 3 //数出现次数

  The positions: 1 4 9

  #include

  #define M 10

  int fun(int *a, int *n, int pos[])

  { int i, k, max=-32767;

  (1)

  for(i=0; i  if( (2) ) max=a[i];

  for(i=0; i  if( (3) ) pos[k++]=i;

  *n=k;

  return max;

  }

  main()

  { int a[M], pos[M], i=0, j, n;

  printf("Enter 10 number :");

  for(i=0; i  j=fun( (5) );

  printf("The max: %d\n", j);

  printf("Total: %d",n);

  printf("The position:");

  for(i=0; i  printf("\n");

  }