【计算机类职业资格】计算机二级(C)上机考试8及答案解析.doc

上传人:testyield361 文档编号:1337783 上传时间:2019-10-17 格式:DOC 页数:2 大小:30KB
下载 相关 举报
【计算机类职业资格】计算机二级(C)上机考试8及答案解析.doc_第1页
第1页 / 共2页
【计算机类职业资格】计算机二级(C)上机考试8及答案解析.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

1、计算机二级(C)上机考试 8及答案解析(总分:-3.00,做题时间:120 分钟)1.填空题 请补充函数 fun(),该函数的功能是:把字符串 str中的字符按字符的 ASCII码降序排列,处理后的字符串仍然保存在原串中,字符串及其长度作为函数参数传入。 例如,如果输入“cdefgh”,则输出为“hgfedc”。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。 试题程序: #include #define N 80 void fun(char s,int n) int i, j; char ch; for(

2、i=0;i填空项 1:_2.改错题 下列给定程序中,函数 fun()的功能是:在字符串 str中找出 ASC码值最小的字符,将其放在第一个位置上,并将该字符前的原字符向后顺序移动。例如,调用 fun()函数之前给字符串输入fagAgBDh,调用后字符串中的内容为 AfaggBDh。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include /*found*/ void fun(char p) char min, *q; int i=0; min=pi; while (pi!=0) if (minpi) /*fo

3、und*/ p=q+i; min=pi; i+; while(qp) *q=*(q-1); q-; p0=min; main() char str80; printf(“Enter a string: “); gets(str); printf(“/nThe original string: “); puts(str); fun(str); printf(“/nThe string after moving: “); puts(str); printf(“/n/n“); (分数:-1.00)_3.编程题 请编写一个函数 fun(),它的功能是计算并输出给定整数 n的所有因子(不包括 1与自身)

4、的平方和(规定 n的值不大于 100)。 例如:主函数从键盘给输入 n的值为 56,则输出为 sum=1113。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入所编写的若干语句。 试题程序: #include long fun(int n) main() int n; long sum; printf(“Input n:“); scanf(“%d“, sum=fun(n); printf(“sum=%ld/n“, sum); (分数:-1.00)_计算机二级(C)上机考试 8答案解析(总分:-3.00,做题时间:120 分钟)1.填空

5、题 请补充函数 fun(),该函数的功能是:把字符串 str中的字符按字符的 ASCII码降序排列,处理后的字符串仍然保存在原串中,字符串及其长度作为函数参数传入。 例如,如果输入“cdefgh”,则输出为“hgfedc”。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun()的横线上填入所编写的若干表达式或语句。 试题程序: #include #define N 80 void fun(char s,int n) int i, j; char ch; for(i=0;i填空项 1:_ (正确答案:【1】i 【2】sj=si)解析:填空 1:本题采用

6、选择法进行排序。选择法的算法思路是:如果有 n个数则从头到倒数的第 2个数一个一个往后走动,每走动一个数总是将这个数与其后的所有数进行两两比较,在比较时按题目要求的顺序将进行比较的这两个数排序(即交换)。理解了选择法的思路,则此空就非常简单了,应该填 i。填空2:借助第三个变量交换两数的方法,非常重要也非常基础,必须要求掌握。2.改错题 下列给定程序中,函数 fun()的功能是:在字符串 str中找出 ASC码值最小的字符,将其放在第一个位置上,并将该字符前的原字符向后顺序移动。例如,调用 fun()函数之前给字符串输入fagAgBDh,调用后字符串中的内容为 AfaggBDh。 请改正程序中

7、的错误,使它能得到正确结果。 注意:不要改动 main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include /*found*/ void fun(char p) char min, *q; int i=0; min=pi; while (pi!=0) if (minpi) /*found*/ p=q+i; min=pi; i+; while(qp) *q=*(q-1); q-; p0=min; main() char str80; printf(“Enter a string: “); gets(str); printf(“/nThe original string: “

8、); puts(str); fun(str); printf(“/nThe string after moving: “); puts(str); printf(“/n/n“); (分数:-1.00)_正确答案:((1)错误:void fun(char p) 正确:void fun(char *p) (2)错误:p=q+i; 正确:q=p+i; )解析:错误:由于本题中函数的功能是对字符串进行处理,而不是对单个字符进行处理,因此,函数的参数应为字符串指针。 错误 2:使指针 q指向 ASCII码最小的字符 本题解答需要 3个步骤: (1)找到字符串中 ASCII码值最小的字符,并保存。 (2)

9、将该字符复制,并将该字符前面的字符串顺次后移。 (3)将 ASCII码值最小的字符赋给字符串的第 1个字符。找到 ASCII码值最小的字符可以通过定义一个字符 min,该字符初始时等于字符串的第 1个字符,若字符串的下一个字符小于 min,则将下一个字符赋给 min,如此循环到字符尾,即可得到 ASCII码值最小的字符,同时令指针 q指向最小字符。之后对最小字符前面的子串顺次后移,可采用 while语句实现。 此题需要熟练掌握和灵活应用 C语言的字符与整型变量的关系以及字符串操作。 3.编程题 请编写一个函数 fun(),它的功能是计算并输出给定整数 n的所有因子(不包括 1与自身)的平方和(

10、规定 n的值不大于 100)。 例如:主函数从键盘给输入 n的值为 56,则输出为 sum=1113。 注意:部分源程序给出如下。 请勿改动主函数 main和其他函数中的任何内容,仅在函数 fun的花括号中填入所编写的若干语句。 试题程序: #include long fun(int n) main() int n; long sum; printf(“Input n:“); scanf(“%d“, sum=fun(n); printf(“sum=%ld/n“, sum); (分数:-1.00)_正确答案:(long fun(int n) int i; long s=0; for(i=2;i=n-1;i+) /*从 2n-1中找 n的所有因子*/ if(n%i=0) s+=i*i; /*将所有因子求平方加*/ return s; /*将平方和返回*/ )解析:本题的解题思路是用 n逐个去除以 2到 n-1之间的所有数,如果 n能被除尽,则把所得到的一个因子的平方累加到 s中去。

展开阅读全文
相关资源
猜你喜欢
  • ASTM E230 E230M-2011e1 8125 Standard Specification and Temperature-Electromotive Force (emf) Tables for Standardized Thermocouples《标准化热电偶温度电动势关系表的标准规格》.pdf ASTM E230 E230M-2011e1 8125 Standard Specification and Temperature-Electromotive Force (emf) Tables for Standardized Thermocouples《标准化热电偶温度电动势关系表的标准规格》.pdf
  • ASTM E230 E230M-2012 red 6793 Standard Specification and Temperature-Electromotive Force (emf) Tables for Standardized Thermocouples《标准化热电偶用标准规范和温度电动势 (emf) 图表》.pdf ASTM E230 E230M-2012 red 6793 Standard Specification and Temperature-Electromotive Force (emf) Tables for Standardized Thermocouples《标准化热电偶用标准规范和温度电动势 (emf) 图表》.pdf
  • ASTM E230 E230M-2017 red 2500 Standard Specification for Temperature-Electromotive Force (emf) Tables for Standardized Thermocouples《标准化热电偶用温度电动势(emf)图表的标准规格》.pdf ASTM E230 E230M-2017 red 2500 Standard Specification for Temperature-Electromotive Force (emf) Tables for Standardized Thermocouples《标准化热电偶用温度电动势(emf)图表的标准规格》.pdf
  • ASTM E230-2003 Standard Specification and Temperature-Electromotive Force (EMF) Tables for Standardized Thermocouples《标准化热电偶用标准规范和温度-电动势(EMF)图表》.pdf ASTM E230-2003 Standard Specification and Temperature-Electromotive Force (EMF) Tables for Standardized Thermocouples《标准化热电偶用标准规范和温度-电动势(EMF)图表》.pdf
  • ASTM E235 E235M-2012 red 6806 Standard Specification for Type K and Type N Mineral-Insulated Metal-Sheathed Thermocouples for Nuclear or for Other High-Reliability Applications《核设施.pdf ASTM E235 E235M-2012 red 6806 Standard Specification for Type K and Type N Mineral-Insulated Metal-Sheathed Thermocouples for Nuclear or for Other High-Reliability Applications《核设施.pdf
  • ASTM E235 E235M-2012(2018) 0000 Standard Specification for Type K and Type N Mineral-Insulated Metal-Sheathed Thermocouples for Nuclear or for Other High-Reliability Applications《核.pdf ASTM E235 E235M-2012(2018) 0000 Standard Specification for Type K and Type N Mineral-Insulated Metal-Sheathed Thermocouples for Nuclear or for Other High-Reliability Applications《核.pdf
  • ASTM E235-2006 Standard Specification for Thermocouples Sheathed Type K and Type N for Nuclear or for Other High-Reliability Applications《核设施或其他高度可靠性设施用K型和N型铠装热电偶标准规范》.pdf ASTM E235-2006 Standard Specification for Thermocouples Sheathed Type K and Type N for Nuclear or for Other High-Reliability Applications《核设施或其他高度可靠性设施用K型和N型铠装热电偶标准规范》.pdf
  • ASTM E236-1966(2006) Standard Specification for Apparatus For Microdetermination Of Alkoxyl Groups《烷氧基团微量测定用仪器》.pdf ASTM E236-1966(2006) Standard Specification for Apparatus For Microdetermination Of Alkoxyl Groups《烷氧基团微量测定用仪器》.pdf
  • ASTM E236-1966(2011) 7500 Standard Specification for Apparatus for Microdetermination of Alkoxyl Groups《烷氧基团微量测定用仪器标准规程》.pdf ASTM E236-1966(2011) 7500 Standard Specification for Apparatus for Microdetermination of Alkoxyl Groups《烷氧基团微量测定用仪器标准规程》.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1