下半年计算机C语言考试题库及答案

时间:2022-08-22 13:37:55 计算机等级 我要投稿
  • 相关推荐

2016年下半年计算机C语言考试题库及答案

  1.下列给定程序中,函数fun的功能是计算如下公式  直到 ,并且把计算结果作为函数值返回。

2016年下半年计算机C语言考试题库及答案

  例如,若形参e的值为1e-3,则函数返回值为0.551690。请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。

  注意:部分源程序在文件BLANK1.C中。

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

  #include

  double fun(double e)

  { int i, k; double s, t, x;

  s=0; k=1; i=2;

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

  x=__1__/4;

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

  while(x __2__ e)

  { s=s+k*x;

  k=k* (-1);

  t=2*i;

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

  x=__3__/(t*t);

  i++;

  }

  return s;

  }

  main()

  { double e=1e-3;

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

  }

  【参考答案】

  (1)3.0或(double)3  (2)>  (3) (t+1)

  2. 下列给定程序中,函数fun的功能是:计算如下公式前n项的和并作为函数值返回。

  例如,当形参n的值为10时,函数返回值为9.612558。

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

  注意:部分源程序在文件BLANK1.C中。

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

  #include

  double fun(int n)

  { int i; double s, t;

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

  s=__1__;

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

  for(i=1; i<=__2__; i++)

  { t=2.0*i;

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

  s=s+(2.0*i-1)*(2.0*i+1)/__3__;

  }

  return s;

  }

  main()

  { int n=-1;

  while(n<0)

  { printf("Please input(n>0): "); scanf("%d",&n); }

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

  }

  【参考答案】

  (1) 0  (2) n  (3) (t*t)

  3.给定程序中,函数fun的功能是:统计形参s所指的字符串中数字字符出现的次数,并存放在形参t所指的变量中,最后在主函数中输出。例如,若形参s所指的字符串为abcdef35adgh3kjsdf7,则输出结果为4。

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

  注意:部分源程序在文件BLANK1.C中。

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

  #include

  void fun(char *s, int *t)

  { int i, n;

  n=0;

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

  for(i=0; ___1___ !=0; i++)

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

  if(s[i]>='0'&&s[i]<= ___2___ ) n++;

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

  ___3___ ;

  }

  main()

  { char s[80]="abcdef35adgh3kjsdf7";

  int t;

  printf("\nThe original string is : %s\n",s);

  fun(s,&t);

  printf("\nThe result is : %d\n",t);

  }

  【参考答案】

  (1) s[i]  (2) '9'  (3)*t=n

  4.下列给定程序中,函数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。

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

  注意:部分源程序在文件BLANK1.C中。

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

  #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");

  n = fun(b, N);

  printf("\nThe number of odd : %d \n", n);

  printf("\nThe odd number :\n");

  for (i=0; i

  printf("\n");

  }

  【参考答案】

  (1)1  (2) j++  (3)j

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

  例如,输入一个整数27638496,函数返回值为64862。

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

  注意:部分源程序在文件BLANK1.C中。

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

  #include

  unsigned long fun(unsigned long n)

  { unsigned long x=0; int t;

  while(n)

  { t=n%10;

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

  if(t%2==____1____)

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

  x=____2____+t;

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

  n=____3____;

  }

  return x;

  }

  main()

  { unsigned long n=-1;

  while(n>99999999||n<0)

  { printf("Please input(0

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

  }

  【参考答案】

  (1)0  (2) 10*x (3)n/10

  6.下列给定程序中,函数fun的功能是:把形参a所指数组中的最小值放在元素a[0]中,接着把a所指数组中的最大值放在a[1]元素中;再把a所指数组元素中的次小值放在a[2]中,把a所指数组元素中的次大值放在a[3],以此类推。

  例如,若a所指数组中的数据最初排列为:9、1、4、2、3、6、5、8、7;则按规则移动后,数据排列为:1、9、2、8、3、7、4、6、5。形参n中存放a所指数组中数据的个数。

  规定fun函数中的max存放当前所找的最大值,px存放当前所找最大值的下标。

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

  注意:部分源程序在文件BLANK1.C中。

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

  # include

  #define N 9

  void fun(int a[], int n)

  { int i,j, max, min, px, pn, t;

  for (i=0; i

  {

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

  max = min = ___1___;

  px = pn = i;

  for (j=i+1; j

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

  if (max<___2___)

  { max = a[j]; px = j; }

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

  if (min>___3___)

  { min = a[j]; pn = j; }

  }

  if (pn != i)

  { t = a[i]; a[i] = min; a[pn] = t;

  if (px == i) px =pn;

  }

  if (px != i+1)

  { t = a[i+1]; a[i+1] = max; a[px] = t; }

  }

  }

  main()

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

  printf("\nThe original data :\n");

  for (i=0; i

  printf("\n");

  fun(b, N);

  printf("\nThe data after moving :\n");

  for (i=0; i

  printf("\n");

  }

  【参考答案】

  (1) a[i]  (2) a[j]  (3) a[j]

  7.下列给定程序中,函数fun的功能是进行数字字符转换。若形参ch中是数字字符'0'~'9',则将'0'转换成'9','1'转换成'8','2'转换成'7',……,'9'转换成'0';若是其它字符则保持不变;并将转换后的结果作为函数值返回。

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

  注意:部分源程序在文件BLANK1.C中。

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

  #include

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

  ___1___ fun(char ch)

  {

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

  if (ch>='0' && ___2___)

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

  return '9'- (ch-___3___);

  return ch ;

  }

  main()

  { char c1, c2;

  printf("\nThe result :\n");

  c1='2'; c2 = fun(c1);

  printf("c1=%c c2=%c\n", c1, c2);

  c1='8'; c2 = fun(c1);

  printf("c1=%c c2=%c\n", c1, c2);

  c1='a'; c2 = fun(c1);

  printf("c1=%c c2=%c\n", c1, c2);

  }

  【参考答案】

  (1) char (2) ch<='9' (3)'0'

  8.下列给定程序中,函数fun的功能是:求ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参n所指的变量中。ss所指字符串数组中共有M个字符串,且串长

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

  注意:部分源程序在文件BLANK1.C中。

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

  #include

  #include

  #define M 5

  #define N 20

  int fun(char (*ss)[N], int *n)

  { int i, k=0, len= N;

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

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

  { len=strlen(ss[i]);

  if(i==0) *n=len;

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

  if(len ___2___ *n)

  { *n=len;

  k=i;

  }

  }

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

  return(___3___);

  }

  main()

  { char ss[M][N]={"shanghai","guangzhou","beijing","tianjing","chongqing"};

  int n,k,i;

  printf("\nThe original strings are :\n");

  for(i=0;i

  k=fun(ss,&n);

  printf("\nThe length of shortest string is : %d\n",n);

  printf("\nThe shortest string is : %s\n",ss[k]);

  }

  【参考答案】

  (1) M  (2) <  (3) k


更多计算机二级相关试题推荐:

1.2016年9月计算机二级C语言试题题库

2.计算机二级C语言笔试历年真题及答案

3.2016下半年计算机二级C语言考试试题及答案

4.计算机二级C语言新增无纸化真题试卷

5.2016年9月计算机二级C语言选择题及答案

6.2016下半年计算机二级C语言预测试题及答案

7.计算机二级C语言试题及答案2016

8.计算机二级C语言考试上机冲刺试题及答案

9.计算机二级c语言题库2016

10.9月计算机二级c语言试题及答案

  9.下列给定程序中,函数fun的功能是:将s所指字符串中的所有数字字符移到所有非数字字符之后,并保持数字字符串和非数字字符串原有的次序。

  例如,s所指的字符串为def35adh3kjsdf7,执行后结果为defadhajsdf3537。

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

  注意:部分源程序在文件BLANK1.C中。

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

  #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]="ba3a54j7sd567sdffs";

  printf("\nThe original string is : %s\n",s);

  fun(s);

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

  }

  【参考答案】

  (1)j++或j+=1或++或j=j+1

  (2)s[i]=t1[i]  (3) j

  10下列给定程序中已建立一个带头结点的单向链表,链表中的各结点按结点数据域中的数据递增有序链接。函数fun的功能是:把形参x的值放入一个新结点并插入链表中,使插入后各结点数据域中的数据仍保持递增有序。

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

  注意:部分源程序在文件BLANK1.C中。

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

  #include

  #include

  #define N 8

  typedef struct list

  { int data;

  struct list *next;

  } SLIST;

  void fun( SLIST *h, int x)

  { SLIST *p, *q, *s;

  s=(SLIST *)malloc(sizeof(SLIST));

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

  s->data=___1___;

  q=h;

  p=h->next;

  while(p!=NULL && x>p->data) {

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

  q=___2___;

  p=p->next;

  }

  s->next=p;

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

  q->next=___3___;

  }

  SLIST *creatlist(int *a)

  { SLIST *h,*p,*q; int i;

  h=p=(SLIST *)malloc(sizeof(SLIST));

  for(i=0; i

  { q=(SLIST *)malloc(sizeof(SLIST));

  q->data=a[i]; p->next=q; p=q;

  }

  p->next=0;

  return h;

  }

  void outlist(SLIST *h)

  { SLIST *p;

  p=h->next;

  if (p==NULL) printf("\nThe list is NULL!\n");

  else

  { printf("\nHead");

  do { printf("->%d",p->data); p=p->next; } while(p!=NULL);

  printf("->End\n");

  }

  }

  main()

  { SLIST *head; int x;

  int a[N]={11,12,15,18,19,22,25,29};

  head=creatlist(a);

  printf("\nThe list before inserting:\n"); outlist(head);

  printf("\nEnter a number : "); scanf("%d",&x);

  fun(head,x);

  printf("\nThe list after inserting:\n"); outlist(head);

  }

  【参考答案】

  (1)x  (2)p  (3)s

  11.下列给定程序中,函数fun的功能是:将形参a所指数组中的前半部分元素中的值与后半部分元素中的值对换。形参n中存放数组中数据的个数,若n为奇数,则中间的元素不动。

  例如:若a所指数组中的数据为:1、2、3、4、5、6、7、8、9,则调换后为:6、7、8、9、5、1、2、3、4。

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

  注意:部分源程序在文件BLANK1.C中。

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

  #include

  #define N 9

  void fun(int a[], int n)

  { int i, t, p;

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

  p = (n%2==0)?n/2:n/2+___1___;

  for (i=0; i

  {

  t=a[i];

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

  a[i] = a[p+___2___];

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

  ___3___ = t;

  }

  }

  main()

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

  printf("\nThe original data :\n");

  for (i=0; i

  printf("\n");

  fun(b, N);

  printf("\nThe data after moving :\n");

  for (i=0; i

  printf("\n");

  }

  【参考答案】

  (1)1  (2) i  (3) a[p+i]或*(a+p+i)

  12.下列给定程序中,函数fun的功能是:从形参ss所指字符串数组中,删除所有串长超过k的字符串,函数返回剩余字符串的个数。ss所指字符串数组中共有N个字符串,且串长小于M。

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

  注意:部分源程序在文件BLANK1.C中。

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

  #include

  #include

  #define N 5

  #define M 10

  int fun(char (*ss)[M], int k)

  { int i,j=0,len;

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

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

  { len=strlen(ss[i]);

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

  if(len<= __2__)

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

  strcpy(ss[j++],__3__);

  }

  return j;

  }

  main()

  { char x[N][M]={"Beijing","Shanghai","Tianjing","Nanjing","Wuhan"};

  int i,f;

  printf("\nThe original string\n\n");

  for(i=0;i

  f=fun(x,7);

  printf("The string witch length is less than or equal to 7 :\n");

  for(i=0; i

  }

  【参考答案】

  (1) N  (2) k  (3) ss[i]

  13.下列给定程序中,函数fun的功能是:把形参s所指字符串中下标为奇数的字符右移到下一个奇数位置,最右边被移出字符串的字符绕回放到第一个奇数位置,下标为偶数的字符不动(注:字符串的长度大于等于2)。

  例如,形参s所指字符串为abcdefgh,执行结果为ahcbedgf。

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

  注意:部分源程序在文件BLANK1.C中。

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

  #include

  void fun(char *s)

  { int i, n, k; char c;

  n=0;

  for(i=0; s[i]!='\0'; i++) n++;

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

  if(n%2==0) k=n-___1___ ;

  else k=n-2;

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

  c=___2___ ;

  for(i=k-2; i>=1; i=i-2) s[i+2]=s[i];

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

  s[1]=___3___ ;

  }

  main()

  { char s[80]="abcdefgh";

  printf("\nThe original string is : %s\n",s);

  fun(s);

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

  }

  【参考答案】

  (1) 1  (2) s[k]或*(s+k)  (3) c

  14.下列给定程序中,函数fun的功能是:在形参ss所指字符串数组中查找与形参t所指字符串相同的串,找到后返回该串在字符串数组中的位置(即下标值),若未找到则返回-1。ss所指字符串数组中共有N个内容不同的字符串,且串长小于M。

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

  注意:部分源程序在文件BLANK1.C中。

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

  #include

  #include

  #define N 5

  #define M 8

  int fun(char (*ss)[M],char *t)

  { int i;

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

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

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

  if(strcmp(ss[i],t)==0 ) return __2__ ;

  return -1;

  }

  main()

  { char ch[N][M]={"if","while","switch","int","for"},t[M];

  int n,i;

  printf("\nThe original string\n\n");

  for(i=0;i

  printf("\nEnter a string for search: "); gets(t);

  n=fun(ch,t);

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

  if(n== __3__) printf("\nDon't found!\n");

  else printf("\nThe position is %d .\n",n);

  }

  【参考答案】

  (1)N  (2)i  (3) -1

  15.下列给定程序中已建立了一个带头结点的单向链表,在main函数中将多次调用fun函数,每调用一次,输出链表尾部结点中的数据,并释放该结点,使链表缩短。

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

  注意:部分源程序在文件BLANK1.C中。

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

  #include

  #include

  #define N 8

  typedef struct list

  { int data;

  struct list *next;

  } SLIST;

  void fun( SLIST *p)

  { SLIST *t, *s;

  t=p->next; s=p;

  while(t->next != NULL)

  { s=t;

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

  t=t->___1___;

  }

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

  printf(" %d ",___2___);

  s->next=NULL;

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

  free(___3___);

  }

  SLIST *creatlist(int *a)

  { SLIST *h,*p,*q; int i;

  h=p=(SLIST *)malloc(sizeof(SLIST));

  for(i=0; i

  { q=(SLIST *)malloc(sizeof(SLIST));

  q->data=a[i]; p->next=q; p=q;

  }

  p->next=0;

  return h;

  }

  void outlist(SLIST *h)

  { SLIST *p;

  p=h->next;

  if (p==NULL) printf("\nThe list is NULL!\n");

  else

  { printf("\nHead");

  do { printf("->%d",p->data); p=p->next; } while(p!=NULL);

  printf("->End\n");

  }

  }

  main()

  { SLIST *head;

  int a[N]={11,12,15,18,19,22,25,29};

  head=creatlist(a);

  printf("\nOutput from head:\n"); outlist(head);

  printf("\nOutput from tail: \n");

  while (head->next != NULL){

  fun(head);

  printf("\n\n");

  printf("\nOutput from head again :\n"); outlist(head);

  }

  }

  【参考答案】

  (1)next  (2) t->data  (3) t


更多计算机二级相关试题推荐:

1.2016年9月计算机二级C语言试题题库

2.计算机二级C语言笔试历年真题及答案

3.2016下半年计算机二级C语言考试试题及答案

4.计算机二级C语言新增无纸化真题试卷

5.2016年9月计算机二级C语言选择题及答案

6.2016下半年计算机二级C语言预测试题及答案

7.计算机二级C语言试题及答案2016

8.计算机二级C语言考试上机冲刺试题及答案

9.计算机二级c语言题库2016

10.9月计算机二级c语言试题及答案

【下半年计算机C语言考试题库及答案】相关文章:

2017年计算机二级c语言题库08-30

全国计算机c语言程序设计题库201708-28

计算机基础考试题库及答案03-11

2017年全国计算机二级c语言考试题库08-31

计算机基础考试题库附答案11-01

2017年计算机二级c语言考试真题及答案08-27

2017年计算机c语言二级考试试题及答案08-30

2017年计算机统考试题题库及答案08-29

2017年全国计算机c语言试题及答案08-28

2017年全国计算机c语言程序设计考试试题及答案08-31