英语考试 手机站

[2017年9月计算机二级c语言考试时间]2017年9月计算机二级C语言考试试题附答案

时间:2019-01-07 11:51:15 英语考试 投诉建议

  C 语言是以函数形式提供给用户的,这些函数可方便的调用,并具有多种循环、条件语句控制程序流向,从而使程序完全结构化。以下是关于计算机二级C语言考试试题附答案,希望大家认真练习!

  第1题

  给定程序MODI1.C中函数 fun 的功能是:把在字符串s中出现的每个字符,紧随其后重复出现一次,形成一个新串放在t中,t中字符按原字符串中字符顺序排列。

  例如:当s中的字符串为:"ABAABBCCDDEE"。

  则t中的字符串应为:"AABBCCDDEE"。

  请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

  Modi1.c

  #include

  #include

  #include

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

  void fun (char s,char t) /参考答案:void fun (char *s,char *t)/

  { int i, sl;

  sl = strlen(s);

  for (i=0; i

  { t[2*i] = s[i];

  t[2*i+1] = s[i];

  }

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

  t[2*sl] = '0'; /参考答案:t[2*sl] = '\0';/

  }

  main()

  { char s[100], t[100];

  clrscr();

  printf("\nPlease enter string s:"); scanf("%s", s);

  fun(s, t);

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

  }

  第2题

  给定程序MODI1.C中函数 fun 的功能是:把在字符串s中出现的每个字符, 紧随其后重复出现一次,放在一个新串t中,t中字符按原字符串中逆排列。

  例如:当s中的字符串为:"ABCDE"时,

  则t中的字符串应为:"EEDDCCBBAA"。

  请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

  Modi1.c

  #include

  #include

  #include

  void fun (char *s, char *t)

  { int i, sl;

  sl = strlen(s);

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

  for (i=1; i

  { t[2*i] = s[sl-i-1];

  t[2*i +1] = s[sl-i-1];

  }

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

  t[2*sl] = '0/'; /参考答案:t[2*sl] = '\0';/

  }

  main()

  { char s[100], t[100];

  clrscr();

  printf("\nPlease enter string s:"); scanf("%s", s);

  fun(s, t);

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

  }

  第3题

  给定程序MODI1.C中函数 fun 的功能是:将在字符串s中下标为偶数位置上的字符,紧随其后重复出现一次,放在一个新串t中,t中字符按原字符串中字符的顺序排列。(注意0为偶数)

  例如:当s中的字符串为:"ABCDE"时,

  则t中的字符串应为:"AACCEE"。

  请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

  Modi1.c

  #include

  #include

  #include

  void fun (char *s, char *t)

  { int i, j, sl;

  sl = strlen(s);

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

  for (i=0, j=0; i   { t[2*j] = s[i];

  t[2*j +1] = s[i];

  j++;

  }

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

  t[2*sl] = '\0'; /参考答案:t[2*j]='\0';/

  }

  main()

  { char s[100], t[100];

  clrscr();

  printf("\nPlease enter string s:"); scanf("%s", s);

  fun(s, t);

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

  }

  第4题

  给定程序MODI1.C中函数 fun 的功能是:将在字符串s中下标为奇数位置上的字符,紧随其后重复出现一次,放在一个新串t中,t中字符按原字符串中字符的顺序排列。(注意0为偶数)

  例如:当s中的字符串为:"ABCDEF"时,

  则t中的字符串应为:"BBDDFF"。

  请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

  Modi1.c

  #include

  #include

  #include

  void fun (char *s, char *t)

  { int i, j, sl;

  sl = strlen(s);

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

  for (i=0, j=0; i   { t[2*j] = s[i];

  t[2*j +1] = s[i];

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

  j--; /参考答案:j++/

  }

  t[2*j] = '\0';

  }

  main()

  { char s[100], t[100];

  clrscr();

  printf("\nPlease enter string s:"); scanf("%s", s);

  fun(s, t);

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

  }

  第5题

  给定程序MODI1.C中函数 fun 的功能是:将在字符串s中下标为偶数位置上的字符,紧随其后重复出现一次,放在一个新串t中,t中字符按原字符串中字符出现的逆序排列。(注意0为偶数)

  例如:当s中的字符串为:"ABCDEF"时,

  则t中的字符串应为:"EECCAA"。

  请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

  Modi1.c

  #include

  #include

  #include

  void fun (char *s, char *t)

  { int i, j, sl;

  sl = strlen(s);

  if(sl%2)sl--; else sl-=2;

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

  for (i=sl, j=0; i>=0; i--) /参考答案:for (i=sl, j=0; i>=0; i-=2)/

  { t[2*j] = s[i];

  t[2*j +1] = s[i];

  j++;

  }

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

  t[2*sl] = '\0'; /参考答案:t[2*j] = '\0';/

  }

  main()

  { char s[100], t[100];

  clrscr();

  printf("\nPlease enter string s:"); scanf("%s", s);

  fun(s, t);

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

  }

  第6题

  给定程序MODI1.C中函数 fun 的功能是:将在字符串s中下标为奇数位置上的字符,紧随其后重复出现一次,放在一个新串t中,t中字符按原字符串中字符出现的逆序排列。(注意0为偶数)

  例如:当s中的字符串为:"ABCDEFG"时,

  则t中的字符串应为:"FFDDBB"。

  请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

  Modi1.c

  #include

  #include

  #include

  void fun (char *s, char *t)

  { int i, j, sl;

  sl = strlen(s);

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

  if(sl%2) Sl-=2; else Sl--; /参考答案:if(sl%2) sl-=2; else sl--;/

  for (i=sl, j=0; i>=0; i-=2)

  { t[2*j] = s[i];

  t[2*j +1] = s[i];

  j++;

  }

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

  t[2*sl] = '0'; /参考答案:t[2*j] = '\0';/

  }

  main()

  { char s[100], t[100];

  clrscr();

  printf("\nPlease enter string s:"); scanf("%s", s);

  fun(s, t);

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

  }

  第7题

  给定程序MODI1.C中函数 fun 的功能是:把在字符串s中出现的每个字符,紧随其后重复出现一次,形成一个新串放在t中,且在t中把原相邻字符的位置进行了交换。

  例如:当s中的字符串为:"ABCDE"时,

  则t中的字符串应为:"BBAADDCCEE"。

  请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

  Modi1.c

  #include

  #include

  #include

  void fun (char *s, char *t)

  {

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

  int i, j; /参考答案:int i,j,sl;/

  sl = strlen(s);

  for (i=0, j=0; i   { if (i+1 < sl)

  { t[2*j] = s[i+1]; t[2*j +1] = s[i+1];

  j++;

  }

  t[2*j] = s[i]; t[2*j +1] = s[i];

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

  j--; /参考答案:j++;/

  }

  t[2*sl] = '\0';

  }

  main()

  { char s[100], t[100];

  clrscr();

  printf("\nPlease enter string s:"); scanf("%s", s);

  fun(s, t);

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

  }

  第8题

  给定程序MODI1.C中函数 fun 的功能是:将在字符串s中出现、而未在字符串t中出现的字符形成一个新的字符串放在u中,u中字符按原字符串中字符顺序排列,不去掉重复字符。

  例如:当s = "AABCDE",t = "BDFG"字符。

  u中的字符串为"AACE"。

  请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

  Modi1.c

  #include

  #include

  #include

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

  void fun (char *s, char *t, char u) /参考答案:void fun (char *s, char *t, char *u)

  { int i, j, sl, tl;

  sl = strlen(s); tl = strlen(t);

  for (i=0; i

  { for (j=0; j

  if (s[i] == t[j]) break;

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

  if (j>tl) /参考答案:if (j>=tl)

  *u++ = s[i];

  }

  *u = '\0';

  }

  main()

  { char s[100], t[100], u[100];

  clrscr();

  printf("\nPlease enter string s:"); scanf("%s", s);

  printf("\nPlease enter string t:"); scanf("%s", t);

  fun(s, t, u);

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

  }

  第9题

  给定程序MODI1.C中函数 fun 的功能是:将未在字符串s中出现而在字符串t中出现的字符形成一个新的字符串放在u中,u中字符按原字符串中字符顺序排列,不去掉重复字符。

  例如:当s = "ABCDE",t = "BDFGG"时,

  u中的字符串为"FGG"。

  请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

  Modi1.c

  #include

  #include

  #include

  void fun (char *s, char *t, char *u)

  { int i, j, sl, tl;

  sl = strlen(s); tl = strlen(t);

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

  for (i=0; i

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

  { for (j=0; j

  if (t[i] == s[j]) break;

  if (j>=sl) *u++ = t[i];

  }

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

  u = '\0'; /参考答案 *u = '\0';

  }

  main()

  { char s[100], t[100], u[100];

  clrscr();

  printf("\nPlease enter string s:"); scanf("%s", s);

  printf("\nPlease enter string t:"); scanf("%s", t);

  fun(s, t, u);

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

  }

  第10题

  给定程序MODI1.C中函数 fun 的功能是:将既在字符串s中出现又在字符串t中出现的字符构成一个新的字符串放在u中,u中字符按原字符串中字符顺序排列,不去掉重复字符。

  例如:当s="ABBCDE",t="BDFG"时,u中的字符串为:"BBD"。

  请改正函数fun中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

  Modi1.c

  #include

  #include

  #include

  void fun (char *s, char *t, char *u)

  { int i, j, sl, tl;

  sl = strlen(s); tl = strlen(t);

  for (i=0; i

  { for (j=0; j

  if (s[i] == t[j]) break;

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

  if (j>=tl) /参考答案if (j

  *u++ = s[i];

  }

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

  *u = '0'; /参考答案*u = '\0';

  }

  main()

  { char s[100], t[100], u[100];

  clrscr();

  printf("\nPlease enter string s:"); scanf("%s", s);

  printf("\nPlease enter string t:"); scanf("%s", t);

  fun(s, t, u);

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

《[2017年9月计算机二级c语言考试时间]2017年9月计算机二级C语言考试试题附答案.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

【[2017年9月计算机二级c语言考试时间]2017年9月计算机二级C语言考试试题附答案】相关文章:

英语考试阅读文章欣赏【3篇】11-30

小学四年级英语考试卷精选5篇11-30

小升初英语考试试题范文(通用3篇)11-30

BEC商务英语考试题型(合集六篇)11-30

初中英语考试常见句型范文(精选七篇)11-30

关于英语考试反思500字【四篇】11-16

全国专业技术人员职称英语考试辅导材料一(锦集4篇)11-14

2022成人高考专升本英语考试真题及答案【精选】11-02

五年级下册英语考试试卷分析与竞赛分析【热】10-29

三大技巧助你通过职称英语考试精选5篇10-26